int devnode_mknod(const char *name, const char *major, const char *minor) { struct stat fs; char buf[512]; char *path; char *msg; char *t; path = concat("/dev/", name); for (t=path; *t != '\0'; t++) { if (*t == '!') *t = '/'; } if (stat(path, &fs) == 0) { msg = concat(path, " already exists."); debug(msg); } else { sprintf(buf, "mknod %s b %s %s", path, major, minor); debug(buf); ensure_path(path); system(buf); } return 0; }
bool hierarchical() const { if (relative()) return true; ensure_path(); if (m_path - m_schema <= 2) return false; auto c = m_uri.data(); return c[m_schema + 1] == '/' && c[m_schema + 2] == '/'; }
void ensure_query() const { if (m_query != ncalc) return; ensure_path(); auto length = m_uri.length(); auto c = m_uri.data(); m_query = m_path; while (m_query < length) { switch (c[m_query]) { case '?': case '#': return; } ++m_query; } }
static void setup_env(void) { char *temp; const char *pds = NULL; const char *disp = getenv("DISPLAY"); size_t len; /* Pass on our prefs domain to startx and its inheritors (mainly for * quartz-wm and the Xquartz stub's MachIPC) */ CFBundleRef bundle = CFBundleGetMainBundle(); if(bundle) { CFStringRef pd = CFBundleGetIdentifier(bundle); if(pd) { pds = CFStringGetCStringPtr(pd, 0); } } /* fallback to hardcoded value if we can't discover it */ if(!pds) { pds = LAUNCHD_ID_PREFIX".X11"; } server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1)); if(!server_bootstrap_name) { fprintf(stderr, "X11.app: Memory allocation error.\n"); exit(1); } strcpy(server_bootstrap_name, pds); setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1); len = strlen(server_bootstrap_name); launchd_id_prefix = malloc(sizeof(char) * (len - 3)); if(!launchd_id_prefix) { fprintf(stderr, "X11.app: Memory allocation error.\n"); exit(1); } strlcpy(launchd_id_prefix, server_bootstrap_name, len - 3); /* We need to unset DISPLAY if it is not our socket */ if(disp) { /* s = basename(disp) */ const char *d, *s; for(s = NULL, d = disp; *d; d++) { if(*d == '/') s = d + 1; } if(s && *s) { if(strcmp(launchd_id_prefix, "org.x") == 0 && strcmp(s, ":0") == 0) { fprintf(stderr, "X11.app: Detected old style launchd DISPLAY, please update xinit.\n"); } else { temp = (char *)malloc(sizeof(char) * len); if(!temp) { fprintf(stderr, "X11.app: Memory allocation error creating space for socket name test.\n"); exit(1); } strlcpy(temp, launchd_id_prefix, len); strlcat(temp, ":0", len); if(strcmp(temp, s) != 0) { /* If we don't have a match, unset it. */ fprintf(stderr, "X11.app: DISPLAY (\"%s\") does not match our id (\"%s\"), unsetting.\n", disp, launchd_id_prefix); unsetenv("DISPLAY"); } free(temp); } } else { /* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */ fprintf(stderr, "X11.app: DISPLAY does not look like a launchd set variable, unsetting.\n"); unsetenv("DISPLAY"); } } /* Make sure PATH is right */ ensure_path(X11BINDIR); /* cd $HOME */ temp = getenv("HOME"); if(temp != NULL && temp[0] != '\0') chdir(temp); }