Example #1
0
static void SOL_ATTR_NO_RETURN
on_fork(void *data)
{
    struct subprocess_data *mdata = data;

    close(mdata->pipes.out[1]);
    close(mdata->pipes.err[0]);
    close(mdata->pipes.in[0]);
    close(STDOUT_FILENO);
    close(STDIN_FILENO);
    close(STDERR_FILENO);

    /* dup2 is acceptable because we want the pipes to not be FD_CLOEXEC */
    if (dup2(mdata->pipes.out[0], STDIN_FILENO) < 0)
        goto err;
    if (dup2(mdata->pipes.in[1], STDOUT_FILENO) < 0)
        goto err;
    if (dup2(mdata->pipes.err[1], STDERR_FILENO) < 0)
        goto err;

    execl("/bin/sh", "sh", "-c", mdata->command, (char *)0);

/*
 * An error happened, just exiting with the error to be catch by the parent
 */
err:
    SOL_WRN("Failed in setup the files descriptors");
    close(mdata->pipes.out[1]);
    close(mdata->pipes.err[0]);
    close(mdata->pipes.in[0]);
    sol_platform_linux_fork_run_exit(-errno);
}
Example #2
0
static void
on_fork(void *data)
{
    unsigned i;

    static const char *daemon_possible_paths[] = {
        "/usr/libexec/bluetooth/bluetoothd", // fedora/yocto-style
        "/usr/lib/bluetooth/bluetoothd", // arch-style
        "/usr/sbin/bluetoothd" // debian-style
    };

    const char *argv[] = {
        NULL, // waiting to be set
        "--nodetach",
        NULL
    };

    static const char *envp[] = {
        "BLUETOOTH_SYSTEM_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket",
        NULL
    };

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(daemon_possible_paths); i++) {
        argv[0] = daemon_possible_paths[i];
        SOL_INF("attempting to exec %s", daemon_possible_paths[i]);
        execvpe(argv[0], (char *const *)argv, (char *const *)envp);
    }

    SOL_INF("bluetooth daemon executable not found, aborting");
    sol_platform_linux_fork_run_exit(EXIT_FAILURE);
}
Example #3
0
static void
on_fork(void *data)
{
    const char *argv[] = {
        "/usr/bin/dbus-daemon",
        "--config-file=/etc/dbus-1/system.conf",
        "--nofork",
        NULL
    };

    if (mkdir("/run/dbus", 0755) < 0 && errno != EEXIST) {
        SOL_WRN("could not create /run/dbus");
        goto error;
    }

    if (access("/etc/dbus-1/system.conf", R_OK) < 0) {
        FILE *fp;

        SOL_INF("/etc/dbus-1/system.conf does not exist, create one as /run/dbus/system.conf");

        fp = fopen("/run/dbus/system.conf", "we");
        if (!fp) {
            SOL_WRN("could not create /run/dbus/system.conf: %s", sol_util_strerrora(errno));
            goto error;
        }

        fputs("<!DOCTYPE busconfig PUBLIC \"-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN\" \"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\">\n"
              "<busconfig>\n"
              "<type>system</type>\n"
              "<listen>unix:path=/run/dbus/system_bus_socket</listen>\n"
              "<policy context=\"default\">\n"
              "<allow user=\"*\"/>\n"
              "<allow own=\"*\"/>\n"
              "<allow send_type=\"method_call\"/>\n"
              "<allow send_type=\"signal\"/>\n"
              "<allow send_type=\"method_return\"/>\n"
              "<allow send_type=\"error\"/>\n"
              "<allow receive_type=\"method_call\"/>\n"
              "<allow receive_type=\"signal\"/>\n"
              "<allow receive_type=\"method_return\"/>\n"
              "<allow receive_type=\"error\"/>\n"
              "</policy>\n"
              "</busconfig>\n",
              fp);
        fclose(fp);
        argv[1] = "--config-file=/run/dbus/system.conf";
    }
    execv(argv[0], (char *const *)argv);

error:
    sol_platform_linux_fork_run_exit(EXIT_FAILURE);
}