]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - lib/plymouth-ctrl.c
2 * plymouth-ctrl.c Simply communications with plymouthd
3 * to avoid forked sub processes and/or
4 * missed plymouth send commands tool
5 * due a plymouthd replacement.
7 * Copyright (c) 2016 SUSE Linux GmbH, All rights reserved.
8 * Copyright (c) 2016 Werner Fink <werner@suse.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program (see the file COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * Author: Werner Fink <werner@suse.de>
35 #include <sys/socket.h>
36 #include <sys/types.h>
43 #include "plymouth-ctrl.h"
45 static int can_read(int fd
, const long timeout
)
49 .events
= POLLIN
|POLLPRI
,
55 ret
= poll(&fds
, 1, timeout
);
56 } while ((ret
< 0) && (errno
== EINTR
));
58 return (ret
== 1) && (fds
.revents
& (POLLIN
|POLLPRI
));
61 static int open_un_socket_and_connect(void)
63 /* The abstract UNIX socket of plymouth */
64 struct sockaddr_un su
= {
65 .sun_family
= AF_UNIX
,
66 .sun_path
= PLYMOUTH_SOCKET_PATH
,
71 fd
= socket(PF_UNIX
, SOCK_STREAM
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, 0);
73 warnx(_("cannot open UNIX socket"));
77 ret
= setsockopt(fd
, SOL_SOCKET
, SO_PASSCRED
, &one
, sizeof(one
));
79 warnx(_("cannot set option for UNIX socket"));
85 /* Note, the abstract PLYMOUTH_SOCKET_PATH has a leading NULL byte */
86 ret
= connect(fd
, (struct sockaddr
*) &su
,
87 offsetof(struct sockaddr_un
, sun_path
) + 1 + strlen(su
.sun_path
+1));
89 if (errno
!= ECONNREFUSED
)
90 warnx(_("cannot connect on UNIX socket"));
99 int plymouth_command(int cmd
, ...)
101 uint8_t answer
[2], command
[2];
102 struct sigaction sp
, op
;
103 int fdsock
= -1, ret
= 0;
105 sigemptyset (&sp
.sa_mask
);
106 sp
.sa_handler
= SIG_IGN
;
107 sp
.sa_flags
= SA_RESTART
;
108 sigaction(SIGPIPE
, &sp
, &op
);
110 /* The plymouthd does read at least two bytes. */
114 fdsock
= open_un_socket_and_connect();
117 write_all(fdsock
, command
, sizeof(command
));
121 fdsock
= open_un_socket_and_connect();
124 write_all(fdsock
, command
, sizeof(command
));
128 warnx(_("the plymouth request %c is not implemented"), cmd
);
135 if (can_read(fdsock
, 1000))
136 read_all(fdsock
, (char *) &answer
[0], sizeof(answer
));
139 sigaction(SIGPIPE
, &op
, NULL
);
140 ret
= (answer
[0] == ANSWER_ACK
) ? 1 : 0;