wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client);
}
-static int
-_tdm_getgrnam_r(const char *name)
-{
- struct group *grp = NULL;
- struct group *grp_res = NULL;
- char* buf = NULL;
- size_t buf_len;
- int ret;
- int id;
-
- buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (buf_len == -1)
- buf_len = 2048;
-
- buf = calloc(1, buf_len * sizeof(char));
- if (!buf) {
- TDM_ERR("creating buffer failed");
- goto failed;
- }
-
- grp = calloc(1, sizeof(struct group));
- if (!grp) {
- TDM_ERR("creating group failed");
- goto failed;
- }
-
- ret = getgrnam_r(name, grp, buf, buf_len, &grp_res);
- if (ret < 0) {
- TDM_ERR("getgrnam_r failed errno:%d(%m)", ret);
- goto failed;
- }
-
- if (grp_res == NULL) {
- TDM_ERR("finding name:%s group failed", name);
- goto failed;
- }
-
- id = grp->gr_gid;
- free(buf);
- free(grp);
-
- return id;
-
-failed:
- /* LCOV_EXCL_START */
-
- if (buf)
- free(buf);
- if (grp)
- free(grp);
-
- return -1;
-
- /* LCOV_EXCL_STOP */
-}
-
-static void
-_tdm_socket_init(tdm_private_loop *private_loop)
-{
- const char *dir = NULL;
- char socket_path[TDM_NAME_LEN * 2];
- int ret = -1, len;
- uid_t uid;
- gid_t gid;
-
- dir = getenv("XDG_RUNTIME_DIR");
- if (!dir) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting XDG_RUNTIME_DIR failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
-
- len = strlen(dir);
- if (len > TDM_NAME_LEN - 1) {
- TDM_ERR("XDG_RUNTIME_DIR is too long\n");
- return;
- }
-
- strncpy(socket_path, dir, TDM_NAME_LEN - 1);
- socket_path[TDM_NAME_LEN - 1] = '\0';
-
- strncat(socket_path, "/tdm-socket", 11);
- socket_path[TDM_NAME_LEN + 10] = '\0';
-
- ret = chmod(socket_path, 509);
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("changing modes of socket file failed:%s (%m)", socket_path);
- return;
-
- /* LCOV_EXCL_STOP */
- }
-
- ret = _tdm_getgrnam_r("root");
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting uid failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
- uid = ret;
-
- ret = _tdm_getgrnam_r("display");
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting gid failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
- gid = ret;
-
- ret = chown(socket_path, uid, gid);
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("changing owner of socket file failed:%s (%m)", socket_path);
- return;
-
- /* LCOV_EXCL_STOP */
- }
-}
-
INTERN tdm_error
tdm_server_init(tdm_private_loop *private_loop)
{
/* LCOV_EXCL_STOP */
}
- _tdm_socket_init(private_loop);
-
private_server = calloc(1, sizeof * private_server);
if (!private_server) {
TDM_ERR("alloc failed");