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

  1. /************************************************************************/  
  2. /*                                                                      */
  3. /* jr .. job repeat. repeat (optionally to kill) current job)           */
  4. /*                                                                      */
  5. /*      usage: jr [-k]  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 kflag = 0, rflag = 0;
  15. uid_t uid;
  16. char *queuename;
  17. char queue[128];
  18. char buff [128];                            
  19. #include "config.h"
  20.                             
  21.  
  22. main (argc, argv, envp)
  23. int argc;
  24. char *argv[], *envp[];
  25. {
  26.     int c;
  27.     extern char *optarg;
  28.     extern int optind;
  29.     while ((c = getopt (argc, argv, "kv")) != -1)
  30.     switch (c)
  31.     {
  32.         case 'k':   kflag = 1;
  33.                     break;
  34.         case 'v':   q_version();
  35.     case '?':   qb_term (-1);
  36.     }
  37.     if (optind >= argc)
  38.     {
  39.         fprintf (stderr, "Usage: jr [-k]  qname\n");
  40.         exit (-1);
  41.     }
  42.     queuename = argv[optind];
  43.     strcpy (queue, QUEUEPATH);
  44.     strcat (queue, queuename);
  45.     qb_setterm();
  46.     fpq = open (queue, O_RDWR);
  47.     if (fpq == -1)
  48.     {
  49.         fprintf (stderr, "Invalid queue name: %s\n", queuename);
  50.         qb_term (-1); 
  51.     }
  52.     q_lock(fpq);
  53.     read  (fpq, &head, sizeof(head));
  54.     if (bad_queue()) qb_exit(-1);
  55.     read  (fpq, &entry, sizeof(entry));
  56.     uid = geteuid();
  57.     if (uid != 0 && uid != entry.qe_uid)
  58.     {
  59.         fprintf (stderr, "Must own the job or be super user to repeat or kill\n");
  60.         qb_term (-1);
  61.     }
  62.     if ((head.qh_flags&qh_repeat) == 0) 
  63.     {
  64.         head.qh_flags += qh_repeat;
  65.     }
  66.     if (kflag)
  67.     {
  68.         if ((head.qh_flags&qh_kill) == 0) 
  69.         {
  70.             head.qh_flags += qh_kill;
  71.         }
  72.     }
  73.     lseek (fpq, 0, SEEK_SET);
  74.     write (fpq, &head, sizeof(head));
  75.     q_unlock(fpq);
  76.     close(fpq); fpq = 0;
  77.     tell_qp();
  78.     qb_term(0);
  79. }
  80.