home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume25 / QBATCH / part01 / src / qh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-04  |  1.9 KB  |  73 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /* qh .. Queue halt. suspend processing of current job in this queue.   */
  4. /*                                                                      */
  5. /*      usage: qh  qname                                      */
  6. /*                                                                      */
  7. /*   Copyright (c) Vita Services 1990                                   */
  8. /*             (c) Vita Fibres   1990 1991                              */
  9. /*                                                                      */
  10. /************************************************************************/
  11.  
  12. #include "qbatch.h"
  13. int fpq = 0;
  14. uid_t uid;
  15. char *queuename;
  16. char queue[128];
  17. char buff[128];
  18. #include "config.h"
  19.  
  20.  
  21. main (argc, argv, envp)
  22. int argc;
  23. char *argv[],
  24.    *envp[];
  25. {
  26.     if (argc == 1)
  27.     {
  28.     puts ("Usage qh queuename");
  29.     qb_term (0);
  30.     }
  31.     if (strcmp(argv[1], "-v") == 0) q_version();
  32.     queuename = argv[1];
  33.     strcpy (queue, QUEUEPATH);
  34.     strcat (queue, queuename);
  35.     qb_setterm();
  36.     fpq = open (queue, O_RDWR);
  37.     if (fpq == -1)
  38.     {
  39.     fprintf (stderr, "Invalid queue name: %s\n", queuename);
  40.     qb_term (-1);
  41.     }
  42.     uid = getuid ();
  43.     if (uid != 0)
  44.     {
  45.     fprintf (stderr, "Must be  super user to halt a queue\n");
  46.     qb_term (-1);
  47.     }
  48.     q_lock(fpq);
  49.     read (fpq, &head, sizeof (head));
  50.     if (bad_queue()) qb_exit(-1);
  51.     if (head.qh_pid == 0)
  52.     {
  53.     fprintf (stderr, "Queue %s is idle\n", queuename);
  54.     qb_term (-1);
  55.     }
  56.     if ((head.qh_flags & qh_halt) == 0)
  57.     {
  58.     head.qh_flags += qh_halt;
  59.     }
  60.     else
  61.     {
  62.     fprintf (stderr, "Queue %s is already halted\n", queuename);
  63.     qb_term (-1);
  64.     }
  65.     lseek (fpq, 0, SEEK_SET);
  66.     write (fpq, &head, sizeof(head));
  67.     q_unlock(fpq);
  68.     close (fpq);
  69.     fpq = 0;
  70.     tell_qp();
  71.     exit (0);
  72. }
  73.