diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-05 11:56:51 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-05 11:56:51 +0200 |
commit | 4f7c28158308563dcad912d87a0031d095d4690a (patch) | |
tree | f8badf11119135268fb58b77e86667b12d0f090c | |
parent | d8221ce9bdd2d7ae6162bed0e1c85e9f7a3ff8f2 (diff) | |
download | pies-4f7c28158308563dcad912d87a0031d095d4690a.tar.gz pies-4f7c28158308563dcad912d87a0031d095d4690a.tar.bz2 |
Write utmp/wtmp records in sysvinit mode.
* configure.ac: Check for utmp.h, utmpx.h
* src/utmp.c: New file.
* src/Makefile.am: Add utmp.c
* src/pies.h (sysvinit_acct): New proto.
* src/progman.c (prog_start, progman_cleanup): Call sysvinit_acct.
* src/sysvinit.c (inittrans): Call sysvinit_acct.
Set proctitle.
-rw-r--r-- | configure.ac | 14 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/pies.h | 11 | ||||
-rw-r--r-- | src/progman.c | 7 | ||||
-rw-r--r-- | src/sysvinit.c | 5 | ||||
-rw-r--r-- | src/utmp.c | 179 |
6 files changed, 214 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 0c1d2b9..5a42270 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -32,25 +32,37 @@ AC_PROG_RANLIB | |||
32 | AC_PROG_YACC | 32 | AC_PROG_YACC |
33 | AC_PROG_LEX | 33 | AC_PROG_LEX |
34 | 34 | ||
35 | # Checks for libraries. | 35 | # Checks for libraries. |
36 | 36 | ||
37 | # Checks for header files. | 37 | # Checks for header files. |
38 | AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h]) | 38 | AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h utmp.h utmpx.h]) |
39 | 39 | ||
40 | # Checks for typedefs, structures, and compiler characteristics. | 40 | # Checks for typedefs, structures, and compiler characteristics. |
41 | AC_TYPE_UID_T | 41 | AC_TYPE_UID_T |
42 | AC_TYPE_MODE_T | 42 | AC_TYPE_MODE_T |
43 | AC_TYPE_PID_T | 43 | AC_TYPE_PID_T |
44 | AC_TYPE_SIZE_T | 44 | AC_TYPE_SIZE_T |
45 | AC_TYPE_SIGNAL | 45 | AC_TYPE_SIGNAL |
46 | 46 | ||
47 | IU_CHECK_MEMBERS([struct msghdr.msg_control, struct msghdr.msg_accrights], , , | 47 | IU_CHECK_MEMBERS([struct msghdr.msg_control, struct msghdr.msg_accrights], , , |
48 | [#include <sys/types.h> | 48 | [#include <sys/types.h> |
49 | #include <sys/socket.h>]) | 49 | #include <sys/socket.h>]) |
50 | 50 | ||
51 | IU_CHECK_MEMBERS([struct utmp.ut_tv, struct utmp.ut_name, | ||
52 | struct utmp.ut_user, struct utmp.ut_time, | ||
53 | struct utmp.ut_host], , , | ||
54 | [#include <utmp.h>]) | ||
55 | |||
56 | if test "$ac_cv_header_utmpx_h" = yes; then | ||
57 | IU_CHECK_MEMBERS([struct utmpx.ut_tv, struct utmpx.ut_name, | ||
58 | struct utmpx.ut_user, struct utmpx.ut_time, | ||
59 | struct utmpx.ut_host], , , | ||
60 | [#include <utmpx.h>]) | ||
61 | fi | ||
62 | |||
51 | # Checks for library functions. | 63 | # Checks for library functions. |
52 | AC_FUNC_CHOWN | 64 | AC_FUNC_CHOWN |
53 | AC_FUNC_FORK | 65 | AC_FUNC_FORK |
54 | AC_CHECK_FUNCS([alarm dup2 gethostbyname memmove memset select setenv socket strchr strcspn strtol strtoul sysconf getdtablesize vsyslog]) | 66 | AC_CHECK_FUNCS([alarm dup2 gethostbyname memmove memset select setenv socket strchr strcspn strtol strtoul sysconf getdtablesize vsyslog]) |
55 | 67 | ||
56 | # Gnulib | 68 | # Gnulib |
diff --git a/src/Makefile.am b/src/Makefile.am index 0fca105..3752eae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -29,12 +29,13 @@ pies_SOURCES = \ | |||
29 | meta1lex.l\ | 29 | meta1lex.l\ |
30 | pies.c\ | 30 | pies.c\ |
31 | progman.c\ | 31 | progman.c\ |
32 | socket.c\ | 32 | socket.c\ |
33 | sysvinit.c\ | 33 | sysvinit.c\ |
34 | url.c\ | 34 | url.c\ |
35 | utmp.c\ | ||
35 | userprivs.c | 36 | userprivs.c |
36 | 37 | ||
37 | noinst_HEADERS = \ | 38 | noinst_HEADERS = \ |
38 | acl.h\ | 39 | acl.h\ |
39 | cmdline.h\ | 40 | cmdline.h\ |
40 | meta1gram.h\ | 41 | meta1gram.h\ |
@@ -453,9 +453,16 @@ struct inetd_builtin | |||
453 | struct inetd_builtin *inetd_builtin_lookup (const char *service, int socktype); | 453 | struct inetd_builtin *inetd_builtin_lookup (const char *service, int socktype); |
454 | 454 | ||
455 | /* sysvinit.c */ | 455 | /* sysvinit.c */ |
456 | void sysvinit_begin (void); | 456 | void sysvinit_begin (void); |
457 | int inittrans (void); | 457 | int inittrans (void); |
458 | int is_comp_wait (struct component *comp); | 458 | int is_comp_wait (struct component *comp); |
459 | 459 | ||
460 | 460 | /* utmp.c */ | |
461 | #define SYSV_ACCT_BOOT 0 | ||
462 | #define SYSV_ACCT_RUNLEVEL 1 | ||
463 | #define SYSV_ACCT_PROC_START 2 | ||
464 | #define SYSV_ACCT_PROC_STOP 3 | ||
465 | |||
466 | void sysvinit_acct (int what, const char *user, const char *id, pid_t pid, | ||
467 | const char *line); | ||
461 | 468 | ||
diff --git a/src/progman.c b/src/progman.c index 15b8c44..97216b8 100644 --- a/src/progman.c +++ b/src/progman.c | |||
@@ -1389,12 +1389,15 @@ prog_start (struct prog *prog) | |||
1389 | disable_socket (prog->v.p.socket); | 1389 | disable_socket (prog->v.p.socket); |
1390 | } | 1390 | } |
1391 | else if (prog->v.p.comp->mode == pies_comp_accept || | 1391 | else if (prog->v.p.comp->mode == pies_comp_accept || |
1392 | prog->v.p.comp->mode == pies_comp_inetd || | 1392 | prog->v.p.comp->mode == pies_comp_inetd || |
1393 | prog->v.p.comp->mode == pies_comp_pass_fd) | 1393 | prog->v.p.comp->mode == pies_comp_pass_fd) |
1394 | close (prog->v.p.socket); | 1394 | close (prog->v.p.socket); |
1395 | else if (is_sysvinit (prog->v.p.comp)) | ||
1396 | sysvinit_acct (SYSV_ACCT_PROC_START, "", prog->tag, pid, ""); | ||
1397 | |||
1395 | prog->pid = pid; | 1398 | prog->pid = pid; |
1396 | prog->v.p.status = status_enabled; | 1399 | prog->v.p.status = status_enabled; |
1397 | debug (1, (_("%s started, pid=%lu"), prog->tag, (unsigned long) pid)); | 1400 | debug (1, (_("%s started, pid=%lu"), prog->tag, (unsigned long) pid)); |
1398 | } | 1401 | } |
1399 | } | 1402 | } |
1400 | 1403 | ||
@@ -2489,16 +2492,20 @@ progman_cleanup (int expect_term) | |||
2489 | react (listener, status, pid); | 2492 | react (listener, status, pid); |
2490 | if (listener->v.p.comp->flags & CF_WAIT) | 2493 | if (listener->v.p.comp->flags & CF_WAIT) |
2491 | enable_socket (listener->v.p.socket); | 2494 | enable_socket (listener->v.p.socket); |
2492 | } | 2495 | } |
2493 | else if (prog->v.p.comp->mode >= pies_mark_sysvinit) | 2496 | else if (prog->v.p.comp->mode >= pies_mark_sysvinit) |
2494 | { | 2497 | { |
2498 | sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog->tag, pid, ""); | ||
2495 | prog->v.p.status = status_finished; | 2499 | prog->v.p.status = status_finished; |
2496 | } | 2500 | } |
2497 | else | 2501 | else |
2498 | { | 2502 | { |
2503 | if (is_sysvinit (prog->v.p.comp)) | ||
2504 | sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog->tag, pid, ""); | ||
2505 | |||
2499 | prog->v.p.status = status_enabled; | 2506 | prog->v.p.status = status_enabled; |
2500 | prog_stop_dependents (prog); | 2507 | prog_stop_dependents (prog); |
2501 | if (!expect_term) | 2508 | if (!expect_term) |
2502 | react (prog, status, pid); | 2509 | react (prog, status, pid); |
2503 | } | 2510 | } |
2504 | break; | 2511 | break; |
diff --git a/src/sysvinit.c b/src/sysvinit.c index 5a0d98a..ef765a1 100644 --- a/src/sysvinit.c +++ b/src/sysvinit.c | |||
@@ -162,25 +162,30 @@ inittrans () | |||
162 | trans = 1; | 162 | trans = 1; |
163 | } | 163 | } |
164 | 164 | ||
165 | switch (boot_state) | 165 | switch (boot_state) |
166 | { | 166 | { |
167 | case sysinit: | 167 | case sysinit: |
168 | break; | ||
168 | case boot: | 169 | case boot: |
170 | sysvinit_acct (SYSV_ACCT_BOOT, "reboot", "~~", 0, "~"); | ||
169 | break; | 171 | break; |
170 | case single0: | 172 | case single0: |
171 | case single1: | 173 | case single1: |
172 | newlevel = 'S'; | 174 | newlevel = 'S'; |
173 | break; | 175 | break; |
174 | case normal: | 176 | case normal: |
175 | /* boot -> normal */ | 177 | /* boot -> normal */ |
176 | newlevel = dfl_level ? dfl_level : initdefault; | 178 | newlevel = dfl_level ? dfl_level : initdefault; |
177 | } | 179 | } |
178 | if (newlevel && newlevel != runlevel) | 180 | if (newlevel && newlevel != runlevel) |
179 | { | 181 | { |
180 | debug (1, ("RL TRANS: %c -> %c", runlevel, newlevel)); | 182 | debug (1, ("RL TRANS: %c -> %c", runlevel, newlevel)); |
183 | sysvinit_acct (SYSV_ACCT_RUNLEVEL, "runlevel", "~~", | ||
184 | newlevel + 256 * runlevel, "~"); | ||
185 | mf_proctitle_format ("init [%c]", newlevel); | ||
181 | runlevel = newlevel; | 186 | runlevel = newlevel; |
182 | trans = 1; | 187 | trans = 1; |
183 | wait = 0; | 188 | wait = 0; |
184 | } | 189 | } |
185 | if (wait) | 190 | if (wait) |
186 | trans = 1; | 191 | trans = 1; |
diff --git a/src/utmp.c b/src/utmp.c new file mode 100644 index 0000000..d4452bc --- /dev/null +++ b/src/utmp.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* This file is part of GNU Pies. | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | GNU Pies is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Pies is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "pies.h" | ||
18 | #include <fcntl.h> | ||
19 | #include <sys/utsname.h> | ||
20 | #include <paths.h> | ||
21 | |||
22 | #ifdef HAVE_UTMPX_H | ||
23 | # include <utmpx.h> | ||
24 | typedef struct utmpx UTMPX; | ||
25 | # if HAVE_UPDWTMPX | ||
26 | # define pies_updwtmpx updwtmpx | ||
27 | # endif | ||
28 | # define GETUTXID getutxid | ||
29 | # undef UTMP_FILE | ||
30 | # define UTMP_FILE UTMPX_FILE | ||
31 | # undef WTMP_FILE | ||
32 | # define WTMP_FILE WTMPX_FILE | ||
33 | # if defined HAVE_STRUCT_UTMPX_UT_NAME | ||
34 | # define UT_NAME(u) ((u)->ut_name) | ||
35 | # elif defined HAVE_STRUCT_UTMPX_UT_USER | ||
36 | # define UT_NAME(u) ((u)->ut_user) | ||
37 | # endif | ||
38 | #else | ||
39 | # include <utmp.h> | ||
40 | typedef struct utmp UTMPX; | ||
41 | # if defined HAVE_STRUCT_UTMP_UT_NAME | ||
42 | # define UT_NAME(u) ((u)->ut_name) | ||