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

  1. /************************************************************************/  
  2. /*                                                                      */
  3. /* qd .. Queue disable. Prevent jobs being submitted to this queue.     */
  4. /*                                                                      */
  5. /*      usage: qd  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. int pid;
  15. char *queuename;
  16. char queue[128];
  17. char buff [128];                            
  18. #include "config.h"
  19.                             
  20. main (argc, argv, envp)
  21. int argc;
  22. char *argv[], *envp[];
  23. {
  24.     if (getuid() != 0)
  25.     {
  26.         fprintf (stderr, "Must be root to disable a queue\n");
  27.         exit (-1);
  28.     }
  29.     if (argc == 1)
  30.     {
  31.         puts ("Usage qd queuename");
  32.         qb_term (0);
  33.     }
  34.     if (strcmp(argv[1], "-v") == 0) q_version();
  35.     queuename = argv[1];
  36.     strcpy (queue, QUEUEPATH);
  37.     strcat (queue, queuename);
  38.     qb_setterm();
  39.     fpq = open (queue, O_RDWR);
  40.     if (fpq == -1)
  41.     {
  42.         fprintf (stderr, "Invalid queue name: %s\n", queuename);
  43.         qb_term (-1); 
  44.     }
  45.     pid = getuid();
  46.     if (pid != 0)
  47.     {
  48.         fprintf (stderr, "Must be  super user to disable a queue\n");
  49.         qb_term (-1);
  50.     }
  51.     q_lock(fpq);
  52.     read  (fpq, &head, sizeof(head));
  53.     if (bad_queue()) qb_exit(-1);
  54.     if ((head.qh_flags&qh_enabled) != 0) 
  55.     {
  56.         head.qh_flags -= qh_enabled;
  57.     }
  58.     else
  59.     {
  60.         fprintf (stderr, "Queue %s is already disabled\n", queuename);
  61.         qb_term (-1);
  62.     }
  63.     lseek (fpq, 0, SEEK_SET);
  64.     write (fpq, &head, sizeof(head));
  65.     qb_term(0);
  66. }
  67.