setlocale() in cron

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

setlocale() in cron

Jan Stary
Why does cron(8) and crontab(1) need to setlocale()?

        Jan


Index: cron.c
===================================================================
RCS file: /cvs/src/usr.sbin/cron/cron.c,v
retrieving revision 1.77
diff -u -p -r1.77 cron.c
--- cron.c 23 Oct 2017 15:15:22 -0000 1.77
+++ cron.c 10 Feb 2020 12:12:13 -0000
@@ -28,7 +28,6 @@
 #include <err.h>
 #include <errno.h>
 #include <grp.h>
-#include <locale.h>
 #include <poll.h>
 #include <signal.h>
 #include <stdio.h>
@@ -83,8 +82,6 @@ main(int argc, char *argv[])
  struct sigaction sact;
  sigset_t blocked, omask;
  struct group *grp;
-
- setlocale(LC_ALL, "");
 
  setvbuf(stdout, NULL, _IOLBF, 0);
  setvbuf(stderr, NULL, _IOLBF, 0);
Index: crontab.c
===================================================================
RCS file: /cvs/src/usr.sbin/cron/crontab.c,v
retrieving revision 1.93
diff -u -p -r1.93 crontab.c
--- crontab.c 28 Jun 2019 13:32:47 -0000 1.93
+++ crontab.c 10 Feb 2020 12:12:13 -0000
@@ -26,7 +26,6 @@
 #include <err.h>
 #include <errno.h>
 #include <limits.h>
-#include <locale.h>
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -92,7 +91,6 @@ main(int argc, char *argv[])
  user_gid = getgid();
  crontab_gid = getegid();
 
- setlocale(LC_ALL, "");
  openlog(__progname, LOG_PID, LOG_CRON);
 
  setvbuf(stderr, NULL, _IOLBF, 0);

Reply | Threaded
Open this post in threaded view
|

Re: setlocale() in cron

Ingo Schwarze
Hi,

Jan Stary wrote on Mon, Feb 10, 2020 at 01:13:58PM +0100:

> Why does cron(8) and crontab(1) need to setlocale()?

I looked through the *.c files in /usr/src/usr.sbin/cron/
and found the following locale-dependent functions:

atrun.c:      isalpha(3), isupper(3)
cron.c:       strtod(3)
do_command.c: isalnum(3), isprint(3), stravis(3)
entry.c:      isalpha(3), isdigit(3)
env.c:        isspace(3)

Neither strftime(3) nor strptime(3) appear to be used, which would
be common traps in this respect, in particular in programs doing
something with dates and times.

Either way, on OpenBSD, none of these functions actually depend on
the locale.

Even if there were something locale-dependent in cron(8), and even
if we consider somebody using these program in a portable way on a
non-OpenBSD system, i believe a daemon started as root should not be
locale-dependent, so i'd like to commit the patch to cron.c in any
case.

While crontab.c does not seem quite as important, i see no possible
harm in cleaning this up, so i'd like to commit that one, too.

OK?
  Ingo


> Index: cron.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/cron/cron.c,v
> retrieving revision 1.77
> diff -u -p -r1.77 cron.c
> --- cron.c 23 Oct 2017 15:15:22 -0000 1.77
> +++ cron.c 10 Feb 2020 12:12:13 -0000
> @@ -28,7 +28,6 @@
>  #include <err.h>
>  #include <errno.h>
>  #include <grp.h>
> -#include <locale.h>
>  #include <poll.h>
>  #include <signal.h>
>  #include <stdio.h>
> @@ -83,8 +82,6 @@ main(int argc, char *argv[])
>   struct sigaction sact;
>   sigset_t blocked, omask;
>   struct group *grp;
> -
> - setlocale(LC_ALL, "");
>  
>   setvbuf(stdout, NULL, _IOLBF, 0);
>   setvbuf(stderr, NULL, _IOLBF, 0);
> Index: crontab.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/cron/crontab.c,v
> retrieving revision 1.93
> diff -u -p -r1.93 crontab.c
> --- crontab.c 28 Jun 2019 13:32:47 -0000 1.93
> +++ crontab.c 10 Feb 2020 12:12:13 -0000
> @@ -26,7 +26,6 @@
>  #include <err.h>
>  #include <errno.h>
>  #include <limits.h>
> -#include <locale.h>
>  #include <pwd.h>
>  #include <signal.h>
>  #include <stdio.h>
> @@ -92,7 +91,6 @@ main(int argc, char *argv[])
>   user_gid = getgid();
>   crontab_gid = getegid();
>  
> - setlocale(LC_ALL, "");
>   openlog(__progname, LOG_PID, LOG_CRON);
>  
>   setvbuf(stderr, NULL, _IOLBF, 0);
>

Reply | Threaded
Open this post in threaded view
|

Re: setlocale() in cron

Todd C. Miller-3
On Mon, 10 Feb 2020 22:16:04 +0100, Ingo Schwarze wrote:

> Even if there were something locale-dependent in cron(8), and even
> if we consider somebody using these program in a portable way on a
> non-OpenBSD system, i believe a daemon started as root should not be
> locale-dependent, so i'd like to commit the patch to cron.c in any
> case.
>
> While crontab.c does not seem quite as important, i see no possible
> harm in cleaning this up, so i'd like to commit that one, too.

I think these are both fine.  In theory the date in the second line
of the crontab comment block could be locale-dependent but that is
not supposed to be user-visible anyway.

 - todd

Reply | Threaded
Open this post in threaded view
|

Re: setlocale() in cron

Ingo Schwarze
In reply to this post by Jan Stary
Hi,

Jan Stary wrote on Mon, Feb 10, 2020 at 01:13:58PM +0100:

> Why does cron(8) and crontab(1) need to setlocale()?

Committed; thanks to millert@ for cross-checking.
  Ingo


> Index: cron.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/cron/cron.c,v
> retrieving revision 1.77
> diff -u -p -r1.77 cron.c
> --- cron.c 23 Oct 2017 15:15:22 -0000 1.77
> +++ cron.c 10 Feb 2020 12:12:13 -0000
> @@ -28,7 +28,6 @@
>  #include <err.h>
>  #include <errno.h>
>  #include <grp.h>
> -#include <locale.h>
>  #include <poll.h>
>  #include <signal.h>
>  #include <stdio.h>
> @@ -83,8 +82,6 @@ main(int argc, char *argv[])
>   struct sigaction sact;
>   sigset_t blocked, omask;
>   struct group *grp;
> -
> - setlocale(LC_ALL, "");
>  
>   setvbuf(stdout, NULL, _IOLBF, 0);
>   setvbuf(stderr, NULL, _IOLBF, 0);
> Index: crontab.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/cron/crontab.c,v
> retrieving revision 1.93
> diff -u -p -r1.93 crontab.c
> --- crontab.c 28 Jun 2019 13:32:47 -0000 1.93
> +++ crontab.c 10 Feb 2020 12:12:13 -0000
> @@ -26,7 +26,6 @@
>  #include <err.h>
>  #include <errno.h>
>  #include <limits.h>
> -#include <locale.h>
>  #include <pwd.h>
>  #include <signal.h>
>  #include <stdio.h>
> @@ -92,7 +91,6 @@ main(int argc, char *argv[])
>   user_gid = getgid();
>   crontab_gid = getegid();
>  
> - setlocale(LC_ALL, "");
>   openlog(__progname, LOG_PID, LOG_CRON);
>  
>   setvbuf(stderr, NULL, _IOLBF, 0);