Skip to content

Commit

Permalink
Bug fix for ppc64 and s390/x
Browse files Browse the repository at this point in the history
that is avoid arg0 of a program be missed in the
console library.

Signed-off-by: Werner Fink <[email protected]>
  • Loading branch information
bitstreamout committed Dec 3, 2021
1 parent fcb9e0c commit f2f8b05
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions blogctl.8
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ This let the daemon disconnect from system console.
.TP
.B reactivate
Whereas this cause the daemon reconnect to system console.
.TP
.B final
Evoke the daemon to rename an already open log file
.I /var/log/boot.log
to the new name
.I /var/log/boot.old
as well as mask it own program name in the process table
with the @ character.
.SH SEE ALSO
.BR blogd (8),
.BR systemd (1),
Expand Down
3 changes: 2 additions & 1 deletion blogd.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ static volatile pid_t pid = -1;

static void flush_handler (void) attribute((noinline));
static void exit_handler (void) attribute((noinline));
volatile char *arg0;

/*
* Now do the job
Expand All @@ -230,6 +229,7 @@ int main(int argc, char *argv[])
{
char ptsname[NAME_MAX+1];
const char *tty, *stt;
volatile char *arg0;
struct console *c;
struct termios o;
struct winsize w;
Expand All @@ -248,6 +248,7 @@ int main(int argc, char *argv[])
warn("could not tell system to show its status");

arg0 = (volatile char*)argv[0];
remember_arg0(arg0);

while ((arg = getopt(argc, argv, "f")) != -1) {
switch (arg) {
Expand Down
18 changes: 14 additions & 4 deletions libconsole/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@
#endif

int final = 0;
extern volatile char *arg0;
static volatile char *_arg0;

/*
* Avoid trouble if linked with e.g. blogger as there
* is no external arg0 but linker on ppc64 and s390/x
* seems to expect this.
*/
void remember_arg0(volatile char *arg0)
{
_arg0 = arg0;
}

/*
* Used to ignore some signals during epoll_pwait(2) or ppoll(2)
Expand Down Expand Up @@ -1044,13 +1054,13 @@ static void socket_handler(int fd)
enqry = ANSWER_ACK;
safeout(fd, enqry, strlen(enqry)+1, SSIZE_MAX);

if (!final) {
if (!final && _arg0) {
int ret;

final = 1;

if (arg0[0] != '@')
arg0[0] = '@';
if (_arg0[0] != '@')
_arg0[0] = '@';

ret = rename(BOOT_LOGFILE, BOOT_OLDLOGFILE);
if (ret < 0) {
Expand Down
1 change: 1 addition & 0 deletions libconsole/libconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ extern int evmax;
extern volatile sig_atomic_t signaled;
extern volatile sig_atomic_t nsigsys;

extern void remember_arg0(volatile char *arg0);
extern ssize_t safein (int fd, void *ptr, size_t s);
extern void safeout (int fd, const void *ptr, size_t s, ssize_t max);

Expand Down

0 comments on commit f2f8b05

Please sign in to comment.