Exemplo n.º 1
0
static char *
_getUniqueId(void)
{
	char		*args[10];
	char		*execResults;
	char		newkey[LOCK_KEY_MAXLEN];
	hrtime_t	hretime;
	int		b;
	int		execStatus;
	struct tm	tstruct;
	time_t		thetime;

	/*
	 * try and use makeuuid to generate a unique i.d. Such a unique i.d.
	 * will look like:
	 *		7814e3c1-1dd2-11b2-9fe8-000d560ddc82
	 */

	args[0] = "makeuuid";
	args[1] = (char *)NULL;

	b = e_ExecCmdList(&execStatus, &execResults, (char *)NULL,
		"/usr/bin/makeuuid", (char *)NULL);

	if ((b == 0) && (execStatus == 0) && (*execResults != '\0')) {
		char	*p;
		p = strpbrk(execResults, " \t\n");
		if (p != (char *)NULL) {
			*p = '\0';
		}
		log_msg(LOG_MSG_DEBUG, MSG_LOCK_GENUID_MAKEUUID,
			execResults);
		return (execResults);
	}

	/*
	 * cannot run makeuuid - generate own unique key - the key is the
	 * same length as unique uid but contains different information that
	 * is as unique as can be made - include current hires time (nanosecond
	 * real timer. Such a unique i.d. will look like:
	 *		0203104092-1145345-0004e94d6af481a0
	 */

	hretime = gethrtime();

	thetime = time((time_t *)NULL);
	(void) localtime_r(&thetime, &tstruct);

	(void) snprintf(newkey, sizeof (newkey),
		"%02d%02d%02d%03d-%02d%02d%02d%d-%016llx", tstruct.tm_mday,
		tstruct.tm_mon, tstruct.tm_year, tstruct.tm_yday,
		tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec,
		tstruct.tm_wday, hretime);

	log_msg(LOG_MSG_DEBUG, MSG_LOCK_GENUID_INTERNAL, newkey);
	return (strdup(newkey));
}
Exemplo n.º 2
0
int
rrmdir(char *a_path)
{
    char	path[PATH_MAX+13];
    int	i;
    int	status;

    /*
     * For some reason, a simple "rm -rf" will remove the contents
     * of the directory, but will fail to remove the directory itself
     * with "No such file or directory" when running the pkg commands
     * under a virtual root via the "chroot" command.  This has been
     * seen so far only with the `pkgremove' command, and when the
     * the directory is NFS mounted from a 4.x server.  This should
     * probably be revisited at a later time, but for now we'll just
     * remove the directory contents first, then the directory.
     */

    /* do not allow removal of all root files via blank path */

    if ((a_path == NULL) || (*a_path == '\0')) {
        (void) fprintf(stderr,
                       pkg_gt("warning: rrmdir(path==NULL): nothing deleted\n"));
        return (0);
    }

    /*
     * first generate path with slash-star at the end and attempt to remove
     * all files first. If successful then remove with just the path only.
     */

    (void) snprintf(path, sizeof (path), "%s/", a_path);
    i = e_ExecCmdList(&status, (char **)NULL, (char *)NULL,
                      "/bin/rm", "rm", "-rf", path, (char *)NULL);

    if (access(a_path, F_OK) == 0) {
        i = e_ExecCmdList(&status, (char **)NULL, (char *)NULL,
                          "/bin/rmdir", "rmdir", a_path, (char *)NULL);
    }

    /* return 0 if last command successful, else return 1 */
    return ((i == 0 && status == 0) ? 0 : 1);
}