/* we need to fill in only namespace information */ int ns_read(pid_t pid, proc_t *ns_task) { struct stat st; char buff[50]; int i, rc = 0; for (i = 0; i < NUM_NS; i++) { snprintf(buff, sizeof(buff), "/proc/%i/ns/%s", pid, get_ns_name(i)); if (stat(buff, &st)) { if (errno != ENOENT) rc = errno; ns_task->ns[i] = 0; continue; } ns_task->ns[i] = st.st_ino; } return rc; }
/* * CREATE COLLATION */ void define_collation(struct list * names, struct list * parameters) { char *collName; oid_t collNamespace; acl_result_e aclresult; struct list_cell *pl; DefElem *fromEl = NULL; DefElem *localeEl = NULL; DefElem *lccollateEl = NULL; DefElem *lcctypeEl = NULL; char *collcollate = NULL; char *collctype = NULL; oid_t newoid; collNamespace = qualified_name_get_creation_ns(names, &collName); aclresult = ns_aclcheck(collNamespace, get_uid(), ACL_CREATE); if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, ACL_KIND_NAMESPACE, get_ns_name(collNamespace)); foreach(pl, parameters) { DefElem* defel = (DefElem *) lfirst(pl); DefElem** defelp; if (pg_strcasecmp(defel->defname, "from") == 0) defelp = &fromEl; else if (pg_strcasecmp(defel->defname, "locale") == 0) defelp = &localeEl; else if (pg_strcasecmp(defel->defname, "lc_collate") == 0) defelp = &lccollateEl; else if (pg_strcasecmp(defel->defname, "lc_ctype") == 0) defelp = &lcctypeEl; else { ereport(ERROR, ( errcode(E_SYNTAX_ERROR), errmsg("collation attribute \"%s\" not recognized", defel->defname))); break; } *defelp = defel; }
static char *format_type_internal(oid_t type_oid, int32 typemod, bool typemod_given, bool allow_invalid) { bool with_typemod = typemod_given && (typemod >= 0); struct heap_tuple * tuple; Form_pg_type typeform; oid_t array_base_type; bool is_array; char *buf; if (type_oid == INVALID_OID && allow_invalid) return pstrdup("-"); tuple = search_syscache1(TYPEOID, OID_TO_D(type_oid)); if (!HT_VALID(tuple)) { if (allow_invalid) return pstrdup("???"); else elog(ERROR, "cache lookup failed for type %u", type_oid); } typeform = (Form_pg_type) GET_STRUCT(tuple); /* * Check if it's a regular (variable length) array type. Fixed-length * array types such as "name" shouldn't get deconstructed. As of * Postgres 8.1, rather than checking typlen we check the toast * property, and don't deconstruct "plain storage" array types --- this * is because we don't want to show oid_vector_s as oid[]. */ array_base_type = typeform->typelem; if (array_base_type != INVALID_OID && typeform->typstorage != 'p') { /* Switch our attention to the array element type */ release_syscache(tuple); tuple = search_syscache1(TYPEOID, OID_TO_D(array_base_type)); if (!HT_VALID(tuple)) { if (allow_invalid) return pstrdup("???[]"); else elog(ERROR, "cache lookup failed for type %u", type_oid); } typeform = (Form_pg_type) GET_STRUCT(tuple); type_oid = array_base_type; is_array = true; } else { is_array = false; } /* * See if we want to special-case the output for certain built-in types. * Note that these special cases should all correspond to special * productions in gram.y, to ensure that the type name will be taken as * a system type, not a user type of the same name. * * If we do not provide a special-case output here, the type name will * be handled the same way as a user type name --- in particular, it * will be double-quoted if it matches any lexer keyword. * * This behavior is essential for some cases, such as types "bit" and * "char". */ buf = NULL; /* flag for no special case */ switch (type_oid) { case BITOID: if (with_typemod) { buf = printTypmod("bit", typemod, typeform->typmodout); } else if (typemod_given) { /* * bit with typmod -1 is not the same as BIT, which * means BIT(1) per SQL spec. Report it as the quoted * typename so that parser will not assign a bogus * typmod. */ } else { buf = pstrdup("bit"); } break; case BOOLOID: buf = pstrdup("boolean"); break; case BPCHAROID: if (with_typemod) { buf = printTypmod("character", typemod, typeform->typmodout); } else if (typemod_given) { /* * bpchar with typmod -1 is not the same as CHARACTER, * which means CHARACTER(1) per SQL spec. Report it as * bpchar so that parser will not assign a bogus typmod. */ } else { buf = pstrdup("character"); } break; case FLOAT4OID: buf = pstrdup("real"); break; case FLOAT8OID: buf = pstrdup("double precision"); break; case INT2OID: buf = pstrdup("smallint"); break; case INT4OID: buf = pstrdup("integer"); break; case INT8OID: buf = pstrdup("bigint"); break; case NUMERICOID: if (with_typemod) buf = printTypmod("numeric", typemod, typeform->typmodout); else buf = pstrdup("numeric"); break; case INTERVALOID: if (with_typemod) buf = printTypmod("interval", typemod, typeform->typmodout); else buf = pstrdup("interval"); break; case TIMEOID: if (with_typemod) buf = printTypmod("time", typemod, typeform->typmodout); else buf = pstrdup("time without time zone"); break; case TIMETZOID: if (with_typemod) buf = printTypmod("time", typemod, typeform->typmodout); else buf = pstrdup("time with time zone"); break; case TIMESTAMPOID: if (with_typemod) buf = printTypmod("timestamp", typemod, typeform->typmodout); else buf = pstrdup("timestamp without time zone"); break; case TIMESTAMPTZOID: if (with_typemod) buf = printTypmod("timestamp", typemod, typeform->typmodout); else buf = pstrdup("timestamp with time zone"); break; case VARBITOID: if (with_typemod) buf = printTypmod("bit varying", typemod, typeform->typmodout); else buf = pstrdup("bit varying"); break; case VARCHAROID: if (with_typemod) buf = printTypmod("character varying", typemod, typeform->typmodout); else buf = pstrdup("character varying"); break; } if (buf == NULL) { /* * Default handling: report the name as it appears in the * catalog. Here, we must qualify the name if it is not visible * in the search path, and we must double-quote it if it's not * a standard identifier or if it matches any keyword. */ char *nspname; char *typname; if (type_is_visible(type_oid)) nspname = NULL; else nspname = get_ns_name(typeform->typnamespace); typname = NAME_TO_STR(typeform->typname); buf = quote_qualified_identifier(nspname, typname); if (with_typemod) buf = printTypmod(buf, typemod, typeform->typmodout); } if (is_array) buf = psnprintf(strlen(buf) + 3, "%s[]", buf); release_syscache(tuple); return buf; }