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

  1. /************************************************************************/  
  2. /*                                                                      */
  3. /* qe .. Queue enable. Enable jobs to be submitted to this queue.       */
  4. /*                                                                      */
  5. /*      usage: qe  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[], *envp[];
  24. {
  25.     if (getuid() != 0)
  26.     {
  27.         fprintf (stderr, "Must be root to enable a queue\n");
  28.         exit (-1);
  29.     }
  30.     if (argc == 1)
  31.     {
  32.         puts ("Usage qe queuename");
  33.         qb_term (0);
  34.     }
  35.     if (strcmp(argv[1], "-v") == 0) q_version();
  36.     queuename = argv[1];
  37.     strcpy (queue, QUEUEPATH);
  38.     strcat (queue, queuename);
  39.     qb_setterm();
  40.     fpq = open (queue, O_RDWR);
  41.     if (fpq == -1)
  42.     {
  43.         fprintf (stderr, "Invalid queue name: %s\n", queuename);
  44.         qb_term (-1); 
  45.     }
  46.     uid = getuid();
  47.     if (uid != 0)
  48.     {
  49.         fprintf (stderr, "Must be  super user to disable a queue\n");
  50.         qb_term (-1);
  51.     }
  52.     q_lock(fpq);
  53.     read  (fpq, &head, sizeof(head));
  54.     if (bad_queue()) qb_exit(-1);
  55.     if ((head.qh_flags&qh_enabled) == 0) 
  56.     {
  57.         head.qh_flags += qh_enabled;
  58.     }
  59.     else
  60.     {
  61.         fprintf (stderr, "Queue %s is already enabled\n", queuename);
  62.         qb_term (-1);
  63.     }
  64.     lseek (fpq, 0, SEEK_SET);
  65.     write (fpq, &head, sizeof(head));
  66.     q_unlock(fpq);
  67.     close(fpq); fpq = 0;
  68.     qb_term(0);
  69. }
  70.