View | Details | Raw Unified | Return to bug 17363
Collapse All | Expand All

(-)crontab.c (+26 lines)
Lines 452-457 Link Here
452
}
452
}
453
453
454
454
455
static char *_tmp_path = 0;
456
void
457
static remove_tmp(int sig)
458
{
459
	if (_tmp_path) {
460
		unlink(_tmp_path);
461
	}
462
	exit(ERROR_EXIT);
463
}
464
465
455
/* returns	0	on success
466
/* returns	0	on success
456
 *		-1	on syntax error
467
 *		-1	on syntax error
457
 *		-2	on install error
468
 *		-2	on install error
Lines 464-469 Link Here
464
	entry	*e;
475
	entry	*e;
465
	time_t	now = time(NULL);
476
	time_t	now = time(NULL);
466
	char	**envp = env_init();
477
	char	**envp = env_init();
478
	void (*f[4])();
467
479
468
	if (envp == NULL) {
480
	if (envp == NULL) {
469
		warnx("cannot allocate memory");
481
		warnx("cannot allocate memory");
Lines 472-477 Link Here
472
484
473
	(void) sprintf(n, "tmp.%d", Pid);
485
	(void) sprintf(n, "tmp.%d", Pid);
474
	(void) sprintf(tn, CRON_TAB(n));
486
	(void) sprintf(tn, CRON_TAB(n));
487
488
	/* Set up to remove the temp file if interrupted by a signal. */
489
	f[0] = signal(SIGHUP, remove_tmp);
490
	f[1] = signal(SIGINT, remove_tmp);
491
	f[2] = signal(SIGTERM, remove_tmp);
492
	_tmp_path = tn;
493
475
	if (!(tmp = fopen(tn, "w+"))) {
494
	if (!(tmp = fopen(tn, "w+"))) {
476
		warn("%s", tn);
495
		warn("%s", tn);
477
		return (-2);
496
		return (-2);
Lines 564-569 Link Here
564
		unlink(tn);
583
		unlink(tn);
565
		return (-2);
584
		return (-2);
566
	}
585
	}
586
587
	/* Restore the default signal handlers. */
588
	_tmp_path = 0;
589
	signal(SIGHUP, f[0]);
590
	signal(SIGINT, f[1]);
591
	signal(SIGTERM, f[2]);
592
567
	log_it(RealUser, Pid, "REPLACE", User);
593
	log_it(RealUser, Pid, "REPLACE", User);
568
594
569
	poke_daemon();
595
	poke_daemon();

Return to bug 17363