]>
Commit | Line | Data |
---|---|---|
a8f0b8f2 AM |
1 | From 1222a0d414c52214e1ecc023889595945496acbb Mon Sep 17 00:00:00 2001 |
2 | From: Tomas Mraz <tmraz@fedoraproject.org> | |
3 | Date: Mon, 13 Jul 2015 11:19:55 +0200 | |
4 | Subject: In crontab command use a temporary filename that is ignored by crond. | |
5 | ||
6 | --- | |
7 | src/crontab.c | 23 ++++++++++++----------- | |
8 | 1 file changed, 12 insertions(+), 11 deletions(-) | |
9 | ||
10 | diff --git a/src/crontab.c b/src/crontab.c | |
11 | index d165a06..e7a4878 100644 | |
12 | --- a/src/crontab.c | |
13 | +++ b/src/crontab.c | |
14 | @@ -104,7 +104,7 @@ edit_cmd(void), | |
15 | poke_daemon(void), | |
16 | check_error(const char *), parse_args(int c, char *v[]), die(int) ATTRIBUTE_NORETURN; | |
17 | static int replace_cmd(void), hostset_cmd(void), hostget_cmd(void); | |
18 | -static char *host_specific_filename(const char *filename, int prefix); | |
19 | +static char *host_specific_filename(const char *prefix, const char *suffix); | |
20 | static const char *tmp_path(void); | |
21 | ||
22 | static void usage(const char *msg) ATTRIBUTE_NORETURN; | |
23 | @@ -445,26 +445,27 @@ static const char *tmp_path(void) { | |
24 | return tmpdir ? tmpdir : "/tmp"; | |
25 | } | |
26 | ||
27 | -static char *host_specific_filename(const char *filename, int prefix) | |
28 | +static char *host_specific_filename(const char *prefix, const char *suffix) | |
29 | { | |
30 | /* | |
31 | * For cluster-wide use, where there is otherwise risk of the same | |
32 | - * name being generated on more than one host at once, prefix with | |
33 | - * "hostname." or suffix with ".hostname" as requested, and return | |
34 | - * static buffer or NULL on failure. | |
35 | + * name being generated on more than one host at once, insert hostname | |
36 | + * separated with dots, and return static buffer or NULL on failure. | |
37 | */ | |
38 | ||
39 | static char safename[MAX_FNAME]; | |
40 | - char hostname[MAXHOSTNAMELEN]; | |
41 | + char hostname[MAX_FNAME]; | |
42 | ||
43 | if (gethostname(hostname, sizeof hostname) != 0) | |
44 | return NULL; | |
45 | ||
46 | if (prefix) { | |
47 | - if (!glue_strings(safename, sizeof safename, hostname, filename, '.')) | |
48 | + if (!glue_strings(safename, sizeof safename, prefix, hostname, '.')) | |
49 | return NULL; | |
50 | - } else { | |
51 | - if (!glue_strings(safename, sizeof safename, filename, hostname, '.')) | |
52 | + strcpy(hostname, safename); | |
53 | + } | |
54 | + if (suffix) { | |
55 | + if (!glue_strings(safename, sizeof safename, hostname, suffix, '.')) | |
56 | return NULL; | |
57 | } | |
58 | ||
59 | @@ -745,7 +746,7 @@ static int replace_cmd(void) { | |
60 | char *safename; | |
61 | ||
62 | ||
63 | - safename = host_specific_filename("tmp.XXXXXXXXXX", 1); | |
64 | + safename = host_specific_filename("#tmp", "XXXXXXXXXX"); | |
65 | if (!safename || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR, | |
66 | safename, '/')) { | |
67 | TempFilename[0] = '\0'; | |
68 | @@ -911,7 +912,7 @@ static int hostset_cmd(void) { | |
69 | if (!HostSpecified) | |
70 | gethostname(Host, sizeof Host); | |
71 | ||
72 | - safename = host_specific_filename("tmp.XXXXXXXXXX", 1); | |
73 | + safename = host_specific_filename("#tmp", "XXXXXXXXXX"); | |
74 | if (!safename || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR, | |
75 | safename, '/')) { | |
76 | TempFilename[0] = '\0'; | |
77 | -- | |
78 | cgit v0.11.2 | |
79 |