along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <mqueue.h>
-#include <sys/xattr.h>
#include "sd-event.h"
#include "log.h"
-#include "load-dropin.h"
-#include "load-fragment.h"
#include "strv.h"
#include "mkdir.h"
#include "path-util.h"
#include "smack-util.h"
#include "bus-util.h"
#include "bus-error.h"
+#include "selinux-util.h"
#include "dbus-socket.h"
#include "unit.h"
#include "socket.h"
if (!s->bind_to_device || streq(s->bind_to_device, "lo"))
return 0;
- t = strappenda("/sys/subsystem/net/devices/", s->bind_to_device);
+ t = strjoina("/sys/subsystem/net/devices/", s->bind_to_device);
return unit_add_node_link(UNIT(s), t, false);
}
assert(f);
prefix = strempty(prefix);
- prefix2 = strappenda(prefix, "\t");
+ prefix2 = strjoina(prefix, "\t");
fprintf(f,
"%sSocket State: %s\n"
if (s->smack_ip_in) {
r = mac_smack_apply_ip_in_fd(fd, s->smack_ip_in);
if (r < 0)
- log_unit_error(UNIT(s)->id, "mac_smack_apply_ip_in_fd: %s", strerror(-r));
+ log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_ip_in_fd: %m");
}
if (s->smack_ip_out) {
r = mac_smack_apply_ip_out_fd(fd, s->smack_ip_out);
if (r < 0)
- log_unit_error(UNIT(s)->id, "mac_smack_apply_ip_out_fd: %s", strerror(-r));
+ log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_ip_out_fd: %m");
}
}
if (s->smack) {
r = mac_smack_apply_fd(fd, s->smack);
if (r < 0)
- log_unit_error(UNIT(s)->id, "mac_smack_apply_fd: %s", strerror(-r));
+ log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_fd: %m");
}
}
r = sd_event_add_io(UNIT(s)->manager->event, &p->event_source, p->fd, EPOLLIN, socket_dispatch_io, p);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "Failed to watch listening fds: %s", strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "Failed to watch listening fds: %m");
goto fail;
}
}
if (pid == 0) {
SocketPort *p;
- uid_t uid = (uid_t) -1;
- gid_t gid = (gid_t) -1;
+ uid_t uid = UID_INVALID;
+ gid_t gid = GID_INVALID;
int ret;
default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1);
fail_child:
log_open();
- log_error("Failed to chown socket at step %s: %s", exit_status_to_string(ret, EXIT_STATUS_SYSTEMD), strerror(-r));
+ log_error_errno(r, "Failed to chown socket at step %s: %m", exit_status_to_string(ret, EXIT_STATUS_SYSTEMD));
_exit(ret);
}
return;
fail:
- log_unit_warning(UNIT(s)->id, "%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to kill processes: %m", UNIT(s)->id);
if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
return;
fail:
- log_unit_warning(UNIT(s)->id, "%s failed to run 'stop-pre' task: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'stop-pre' task: %m", UNIT(s)->id);
socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
}
r = socket_watch_fds(s);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to watch sockets: %m", UNIT(s)->id);
goto fail;
}
if (s->control_command) {
r = socket_spawn(s, s->control_command, &s->control_pid);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'start-post' task: %m", UNIT(s)->id);
goto fail;
}
r = socket_open_fds(s);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to listen on sockets: %m", UNIT(s)->id);
goto fail;
}
r = socket_chown(s, &s->control_pid);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to fork 'start-chown' task: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to fork 'start-chown' task: %m", UNIT(s)->id);
goto fail;
}
if (s->control_command) {
r = socket_spawn(s, s->control_command, &s->control_pid);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'start-pre' task: %m", UNIT(s)->id);
goto fail;
}
r = socket_open_fds(s);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to listen on sockets: %m", UNIT(s)->id);
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
return;
}
r = socket_watch_fds(s);
if (r < 0) {
- log_unit_warning(UNIT(s)->id, "%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to watch sockets: %m", UNIT(s)->id);
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
}
}
return;
fail:
- log_unit_warning(UNIT(s)->id, "%s failed to run next task: %s", UNIT(s)->id, strerror(-r));
+ log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run next task: %m", UNIT(s)->id);
if (s->state == SOCKET_START_POST)
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
s->result = SOCKET_SUCCESS;
socket_enter_start_pre(s);
- return 0;
+ return 1;
}
static int socket_stop(Unit *u) {
assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
socket_enter_stop_pre(s, SOCKET_SUCCESS);
- return 0;
+ return 1;
}
static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
LIST_FOREACH(port, p, s->ports)
if (p->type == SOCKET_FIFO &&
- streq_ptr(p->path, value+skip))
+ path_equal_or_files_same(p->path, value+skip))
break;
if (p) {
LIST_FOREACH(port, p, s->ports)
if (p->type == SOCKET_SPECIAL &&
- streq_ptr(p->path, value+skip))
+ path_equal_or_files_same(p->path, value+skip))
break;
if (p) {
LIST_FOREACH(port, p, s->ports)
if (p->type == SOCKET_MQUEUE &&
- streq_ptr(p->path, value+skip))
+ streq(p->path, value+skip))
break;
if (p) {
socket_notify_service_dead(s, se->result == SERVICE_FAILURE_START_LIMIT);
if (se->state == SERVICE_DEAD ||
- se->state == SERVICE_STOP ||
- se->state == SERVICE_STOP_SIGTERM ||
- se->state == SERVICE_STOP_SIGKILL ||
- se->state == SERVICE_STOP_POST ||
se->state == SERVICE_FINAL_SIGTERM ||
se->state == SERVICE_FINAL_SIGKILL ||
se->state == SERVICE_AUTO_RESTART)