diff options
Diffstat (limited to 'coreutils/date.c')
-rw-r--r-- | coreutils/date.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 0fb9f1f00..5b15ce778 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -58,7 +58,8 @@ | |||
58 | //config: the same format. With it on, 'date DATE' additionally supports | 58 | //config: the same format. With it on, 'date DATE' additionally supports |
59 | //config: MMDDhhmm[[YY]YY][.ss] format. | 59 | //config: MMDDhhmm[[YY]YY][.ss] format. |
60 | 60 | ||
61 | //applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP)) | 61 | //applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date)) |
62 | /* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ | ||
62 | 63 | ||
63 | //kbuild:lib-$(CONFIG_DATE) += date.o | 64 | //kbuild:lib-$(CONFIG_DATE) += date.o |
64 | 65 | ||
@@ -66,7 +67,7 @@ | |||
66 | * date [OPTION]... [+FORMAT] | 67 | * date [OPTION]... [+FORMAT] |
67 | * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] | 68 | * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] |
68 | * -d, --date=STRING | 69 | * -d, --date=STRING |
69 | * display time described by STRING, not `now' | 70 | * display time described by STRING, not 'now' |
70 | * -f, --file=DATEFILE | 71 | * -f, --file=DATEFILE |
71 | * like --date once for each line of DATEFILE | 72 | * like --date once for each line of DATEFILE |
72 | * -r, --reference=FILE | 73 | * -r, --reference=FILE |
@@ -152,12 +153,6 @@ enum { | |||
152 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ | 153 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ |
153 | }; | 154 | }; |
154 | 155 | ||
155 | static void maybe_set_utc(int opt) | ||
156 | { | ||
157 | if (opt & OPT_UTC) | ||
158 | putenv((char*)"TZ=UTC0"); | ||
159 | } | ||
160 | |||
161 | #if ENABLE_LONG_OPTS | 156 | #if ENABLE_LONG_OPTS |
162 | static const char date_longopts[] ALIGN1 = | 157 | static const char date_longopts[] ALIGN1 = |
163 | "rfc-822\0" No_argument "R" | 158 | "rfc-822\0" No_argument "R" |
@@ -170,6 +165,19 @@ static const char date_longopts[] ALIGN1 = | |||
170 | ; | 165 | ; |
171 | #endif | 166 | #endif |
172 | 167 | ||
168 | /* We are a NOEXEC applet. | ||
169 | * Obstacles to NOFORK: | ||
170 | * - we change env | ||
171 | * - xasprintf result not freed | ||
172 | * - after xasprintf we use other xfuncs | ||
173 | */ | ||
174 | |||
175 | static void maybe_set_utc(int opt) | ||
176 | { | ||
177 | if (opt & OPT_UTC) | ||
178 | putenv((char*)"TZ=UTC0"); | ||
179 | } | ||
180 | |||
173 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 181 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
174 | int date_main(int argc UNUSED_PARAM, char **argv) | 182 | int date_main(int argc UNUSED_PARAM, char **argv) |
175 | { | 183 | { |
@@ -184,13 +192,16 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
184 | char *filename; | 192 | char *filename; |
185 | char *isofmt_arg = NULL; | 193 | char *isofmt_arg = NULL; |
186 | 194 | ||
187 | opt_complementary = "d--s:s--d" | 195 | opt = getopt32long(argv, "^" |
188 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); | 196 | "Rs:ud:r:" |
189 | IF_LONG_OPTS(applet_long_options = date_longopts;) | 197 | IF_FEATURE_DATE_ISOFMT("I::D:") |
190 | opt = getopt32(argv, "Rs:ud:r:" | 198 | "\0" |
191 | IF_FEATURE_DATE_ISOFMT("I::D:"), | 199 | "d--s:s--d" |
200 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"), | ||
201 | date_longopts, | ||
192 | &date_str, &date_str, &filename | 202 | &date_str, &date_str, &filename |
193 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); | 203 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) |
204 | ); | ||
194 | argv += optind; | 205 | argv += optind; |
195 | maybe_set_utc(opt); | 206 | maybe_set_utc(opt); |
196 | 207 | ||