~ubuntu-branches/ubuntu/natty/cron/natty

« back to all changes in this revision

Viewing changes to crontab.c

  • Committer: Bazaar Package Importer
  • Author(s): Emanuele Gentili
  • Date: 2008-05-12 00:44:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080512004422-467loerydtsjz6gy
Tags: 3.0pl1-104ubuntu1
* Merge from debian unstable, remaining changes: (LP: #229380)
 + Remove stop links from rc0 and rc6.
 + Modify Maintainer value to match the DebianMaintainerField
   specification.
 + Add forgotten versioned-dependency on sysv-rc to get new update-rc.d
  behaviour. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
static  char            Directory[MAX_FNAME];
61
61
static  FILE            *NewCrontab = NULL;
62
62
static  int             CheckErrorCount;
 
63
static  int             PromptOnDelete;
63
64
static  enum opt_t      Option;
64
65
static  struct passwd   *pw;
65
66
static  void            list_cmd __P((void)),
86
87
        fprintf(stderr, "\t-e\t(edit user's crontab)\n");
87
88
        fprintf(stderr, "\t-l\t(list user's crontab)\n");
88
89
        fprintf(stderr, "\t-r\t(delete user's crontab)\n");
 
90
        fprintf(stderr, "\t-i\t(prompt before deleting user's crontab)\n");
89
91
        exit(ERROR_EXIT);
90
92
}
91
93
 
140
142
}
141
143
        
142
144
#if DEBUGGING
143
 
char *getoptarg = "u:lerx:";
 
145
char *getoptarg = "u:lerix:";
144
146
#else
145
 
char *getoptarg = "u:ler";
 
147
char *getoptarg = "u:leri";
146
148
#endif
147
149
 
148
150
 
167
169
        }
168
170
        Filename[0] = '\0';
169
171
        Option = opt_unknown;
 
172
        PromptOnDelete = 0;
170
173
 
171
174
        while (EOF != (argch = getopt(argc, argv, getoptarg))) {
172
175
                switch (argch) {
212
215
                                usage("only one operation permitted");
213
216
                        Option = opt_edit;
214
217
                        break;
 
218
                case 'i':
 
219
                        PromptOnDelete = 1;
 
220
                        break;
215
221
                default:
216
222
                        usage("unrecognized option");
217
223
                }
292
298
        log_it(RealUser, Pid, "LIST", User);
293
299
        (void) snprintf(n, MAX_FNAME, CRON_TAB(User));
294
300
        if (!(f = fopen(n, "r"))) {
295
 
                if (errno == ENOENT)
 
301
                if (errno == ENOENT) 
296
302
                        fprintf(stderr, "no crontab for %s\n", User);
297
 
                else
 
303
                else {
 
304
                        fprintf(stderr, "%s/", CRONDIR);
298
305
                        perror(n);
 
306
                }
299
307
                exit(ERROR_EXIT);
300
308
        }
301
309
 
335
343
static void
336
344
delete_cmd() {
337
345
        char    n[MAX_FNAME];
 
346
        char    q[MAX_TEMPSTR];
 
347
        int     ans;
 
348
 
 
349
        if( PromptOnDelete == 1 )
 
350
        {
 
351
            printf("crontab: really delete %s's crontab? ", User);
 
352
            fflush(stdout);
 
353
            ans = 0;
 
354
            q[0] = '\0';
 
355
            while ( ans == 0 ) {
 
356
                (void) fgets(q, sizeof q, stdin);
 
357
                switch (islower(q[0]) ? q[0] : tolower(q[0])) {
 
358
                    case 'y':
 
359
                    case 'n':
 
360
                        ans = 1;
 
361
                        break;
 
362
                    default:
 
363
                        fprintf(stderr, "Please enter Y or N: ");
 
364
                }
 
365
            }
 
366
            if ( (q[0] == 'N') || (q[0] == 'n') )
 
367
                exit(OK_EXIT);
 
368
        }
338
369
 
339
370
        log_it(RealUser, Pid, "DELETE", User);
340
371
        (void) snprintf(n, MAX_FNAME, CRON_TAB(User));
341
372
        if (unlink(n)) {
342
373
                if (errno == ENOENT)
343
374
                        fprintf(stderr, "no crontab for %s\n", User);
344
 
                else
 
375
                else {
 
376
                        fprintf(stderr, "%s/", CRONDIR);
345
377
                        perror(n);
 
378
                }
346
379
                exit(ERROR_EXIT);
347
380
        }
348
381
        poke_daemon();
509
542
        (void) snprintf(n, MAX_FNAME, CRON_TAB(User));
510
543
        if (!(f = fopen(n, "r"))) {
511
544
                if (errno != ENOENT) {
 
545
                        fprintf(stderr, "%s/", CRONDIR);
512
546
                        perror(n);
513
547
                        exit(ERROR_EXIT);
514
548
                }
765
799
        um = umask(077);
766
800
        fd = mkstemp(tn);
767
801
        if (fd < 0) {
 
802
                fprintf(stderr, "%s/", CRONDIR);
768
803
                perror(tn);
769
804
                return(-2);
770
805
        }
771
806
        tmp = fdopen(fd, "w+");
772
807
        if (!tmp) {
 
808
                fprintf(stderr, "%s/", CRONDIR);
773
809
                perror(tn);
774
810
                return (-2);
775
811
        }
884
920
        tvs[1] = tvs[0];
885
921
        if (utimes(SPOOL_DIR, tvs) < OK) {
886
922
                fprintf(stderr, "crontab: can't update mtime on spooldir\n");
 
923
                fprintf(stderr, "%s/", CRONDIR);
887
924
                perror(SPOOL_DIR);
888
925
                return;
889
926
        }
890
927
#else
891
928
        if (utime(SPOOL_DIR, NULL) < OK) {
892
929
                fprintf(stderr, "crontab: can't update mtime on spooldir\n");
 
930
                fprintf(stderr, "%s/", CRONDIR);
893
931
                perror(SPOOL_DIR);
894
932
                return;
895
933
        }