コード例 #1
0
ファイル: main.c プロジェクト: 14rcole/ostree
static int
callback_open (const char *path, struct fuse_file_info *finfo)
{
  return do_open (path, 0, finfo);
}
コード例 #2
0
/**
 * Create absolute file, returning file descriptor or -1 on error with errno set.
 * Errors are logged as a warning, unless the error is ENOENT which means
 * the directory does not exist.
 */
int
file_create_missing(const char *path, int flags, int mode)
{
	return do_open(path, flags | O_CREAT, mode, TRUE, TRUE, FALSE);
}
コード例 #3
0
ファイル: output.c プロジェクト: anandhis/ompi
/*
 * Reset the parameters on a stream
 */
int opal_output_reopen(int output_id, opal_output_stream_t * lds)
{
    return do_open(output_id, lds);
}
コード例 #4
0
/**
 * Open file, returning file descriptor or -1 on error with errno set.
 * Errors are logged as a warning.
 *
 * This is a perfect replacement for the open() system call, with logging
 * on errors.
 */
int
file_open(const char *path, int flags, int mode)
{
	return do_open(path, flags, mode, FALSE, FALSE, FALSE);
}
コード例 #5
0
/**
 * Open absolute file, returning file descriptor or -1 on error with errno set.
 * Errors are logged as a warning, unless the file is missing, in which
 * case nothing is logged.
 */
int
file_open_missing(const char *path, int flags)
{
	return do_open(path, flags, 0, TRUE, TRUE, FALSE);
}
コード例 #6
0
ファイル: hunt.c プロジェクト: vcosta/greedmud
void hunt_victim( CHAR_DATA *ch )
{
    CHAR_DATA *tmp;
    int        dir;
    bool       found;

    if ( !ch || ch->deleted || !ch->hunting )
        return;

    /*
     * Make sure the victim still exists.
     */
    found = FALSE;
    for ( tmp = char_list; tmp; tmp = tmp->next )
        if ( ch->hunting->who == tmp )
        {
            found = TRUE;
            break;
        }

    if ( !found )
    {
        do_say( ch, "Damn!  My prey is gone!!" );
        stop_hunting( ch );
        return;
    }

    if ( ch->in_room == ch->hunting->who->in_room )
    {
        if ( ch->fighting )
            return;
        found_prey( ch, ch->hunting->who );
        return;
    }

    /*
     * Give a random direction if the mob misses the die roll.
     */
    if ( number_percent( ) > 75 )	/* @ 25% */
    {
        do
        {
            dir = number_door( );
        }
        while (   !( ch->in_room->exit[dir] )
                  || !( ch->in_room->exit[dir]->to_room ) );
    }
    else
    {
        dir = find_path( ch->in_room, ch->hunting->who->in_room,
                         500 + ch->level * 25 );

        if ( dir < 0 )
        {
            act( "$n says 'Damn!  Lost $M!'", ch, NULL, ch->hunting->who,
                 TO_ROOM );
            stop_hunting( ch );
            return;
        }
    }

    {
        EXIT_DATA *pexit;

        pexit = ch->in_room->exit[dir];

        if ( IS_SET( pexit->to_room->room_flags, ROOM_NO_MOB )
                || ( xIS_SET( ch->act, ACT_STAY_AREA )
                     && pexit->to_room->area != ch->in_room->area ) )
        {
            stop_hunting( ch );
            return;
        }

        if ( IS_SET( pexit->exit_info, EX_CLOSED ) )
        {
            do_open( ch, dir_name[dir] );
            return;
        }
    }

    move_char( ch, dir );

    if ( ch->deleted )
    {
        return;
    }

    if ( !ch->hunting )
    {
        if ( !ch->in_room )
        {
            char buf [ MAX_STRING_LENGTH ];

            sprintf( buf, "Hunt_victim: no ch->in_room!  Mob #%d, name: %s.  Placing mob in limbo.",
                     ch->pIndexData->vnum, ch->name );
            bug( buf, 0 );
            char_to_room( ch, get_room_index( ROOM_VNUM_LIMBO ) );
            return;
        }
        do_say( ch, "Damn!  Lost my prey!" );
        return;
    }
    if ( ch->in_room == ch->hunting->who->in_room )
        found_prey( ch, ch->hunting->who );
    return;
}
コード例 #7
0
ファイル: batch.c プロジェクト: HappyBasher/LINBOv3
/* This routine tries to write out an equivalent --read-batch command
 * given the user's --write-batch args.  However, it doesn't really
 * understand most of the options, so it uses some overly simple
 * heuristics to munge the command line into something that will
 * (hopefully) work. */
void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
{
	int fd, i, len, err = 0;
	char *p, filename[MAXPATHLEN];

	stringjoin(filename, sizeof filename,
		   batch_name, ".sh", NULL);
	fd = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC,
		     S_IRUSR | S_IWUSR | S_IXUSR);
	if (fd < 0) {
		rsyserr(FERROR, errno, "Batch file %s open error",
			filename);
		exit_cleanup(RERR_FILESELECT);
	}

	/* Write argvs info to BATCH.sh file */
	if (write_arg(fd, argv[0]) < 0)
		err = 1;
	if (filter_list.head) {
		if (protocol_version >= 29)
			write_sbuf(fd, " --filter=._-");
		else
			write_sbuf(fd, " --exclude-from=-");
	}
	for (i = 1; i < argc - file_arg_cnt; i++) {
		p = argv[i];
		if (strncmp(p, "--files-from", 12) == 0
		    || strncmp(p, "--filter", 8) == 0
		    || strncmp(p, "--include", 9) == 0
		    || strncmp(p, "--exclude", 9) == 0) {
			if (strchr(p, '=') == NULL)
				i++;
			continue;
		}
		if (strcmp(p, "-f") == 0) {
			i++;
			continue;
		}
		if (write(fd, " ", 1) != 1)
			err = 1;
		if (strncmp(p, "--write-batch", len = 13) == 0
		 || strncmp(p, "--only-write-batch", len = 18) == 0) {
			if (write(fd, "--read-batch", 12) != 12)
				err = 1;
			if (p[len] == '=') {
				if (write(fd, "=", 1) != 1
				 || write_arg(fd, p + len + 1) < 0)
					err = 1;
			}
		} else {
			if (write_arg(fd, p) < 0)
				err = 1;
		}
	}
	if (!(p = check_for_hostspec(argv[argc - 1], &p, &i)))
		p = argv[argc - 1];
	if (write(fd, " ${1:-", 6) != 6
	 || write_arg(fd, p) < 0)
		err = 1;
	write_byte(fd, '}');
	if (filter_list.head)
		write_filter_rules(fd);
	if (write(fd, "\n", 1) != 1 || close(fd) < 0 || err) {
		rsyserr(FERROR, errno, "Batch file %s write error",
			filename);
		exit_cleanup(RERR_FILEIO);
	}
}
コード例 #8
0
ファイル: deskmain.c プロジェクト: kelihlodversson/emutos
static WORD do_filemenu(WORD item)
{
    WORD done;
    WORD curr;
    WNODE *pw;

    done = FALSE;
    pw = win_ontop();

    curr = win_isel(G.g_screen, G.g_croot, 0);
    switch(item)
    {
    case OPENITEM:
        if (curr)
            done = do_open(curr);
        break;
    case SHOWITEM:
        if (curr)
            do_info(curr);
        break;
    case NFOLITEM:
        if (pw)
            fun_mkdir(pw);
        break;
    case CLOSITEM:
        if (pw)
            fun_close(pw, CLOSE_FOLDER);
        break;
    case CLSWITEM:
        if (pw)
            fun_close(pw, CLOSE_WINDOW);
        break;
    case DELTITEM:
        if (curr)
            fun_del(curr);
        break;
    case FORMITEM:
        if (curr)
            done = do_format(curr);
        break;

#if WITH_CLI != 0
    case CLIITEM:                         /* Start EmuCON */
        G.g_tail[0] = G.g_tail[1] = 0;
        strcpy(G.g_cmd, "EMUCON");
        done = pro_run(FALSE, 1, -1, -1);
        break;
#endif

#if CONF_WITH_SHUTDOWN
    case QUITITEM:
        enable_ceh = FALSE; /* avoid possibility of useless form_alert()s */
        display_free_stack();
        pro_exit(G.g_cmd, G.g_tail);
        done = TRUE;
        break;
#endif
    }

    return done;
}
コード例 #9
0
ファイル: output.c プロジェクト: 00datman/ompi
/*
 * Open a stream
 */
int pmix_output_open(pmix_output_stream_t * lds)
{
    return do_open(-1, lds);
}
コード例 #10
0
ファイル: util.c プロジェクト: AaronDP/rsync_adbshell
/* Copy a file.  If ofd < 0, copy_file unlinks and opens the "dest" file.
 * Otherwise, it just writes to and closes the provided file descriptor.
 * In either case, if --xattrs are being preserved, the dest file will
 * have its xattrs set from the source file.
 *
 * This is used in conjunction with the --temp-dir, --backup, and
 * --copy-dest options. */
int copy_file(const char *source, const char *dest, int ofd,
	      mode_t mode, int create_bak_dir)
{
	int ifd;
	char buf[1024 * 8];
	int len;   /* Number of bytes read into `buf'. */

	if ((ifd = do_open(source, O_RDONLY, 0)) < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "open %s", full_fname(source));
		errno = save_errno;
		return -1;
	}

	if (ofd < 0) {
		if (robust_unlink(dest) && errno != ENOENT) {
			int save_errno = errno;
			rsyserr(FERROR_XFER, errno, "unlink %s", full_fname(dest));
			errno = save_errno;
			return -1;
		}

		if ((ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0) {
			int save_errno = errno ? errno : EINVAL; /* 0 paranoia */
			if (create_bak_dir && errno == ENOENT && make_bak_dir(dest) == 0) {
				if ((ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0)
					save_errno = errno ? errno : save_errno;
				else
					save_errno = 0;
			}
			if (save_errno) {
				rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(dest));
				close(ifd);
				errno = save_errno;
				return -1;
			}
		}
	}

	while ((len = safe_read(ifd, buf, sizeof buf)) > 0) {
		if (full_write(ofd, buf, len) < 0) {
			int save_errno = errno;
			rsyserr(FERROR_XFER, errno, "write %s", full_fname(dest));
			close(ifd);
			close(ofd);
			errno = save_errno;
			return -1;
		}
	}

	if (len < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "read %s", full_fname(source));
		close(ifd);
		close(ofd);
		errno = save_errno;
		return -1;
	}

	if (close(ifd) < 0) {
		rsyserr(FWARNING, errno, "close failed on %s",
			full_fname(source));
	}

	if (close(ofd) < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "close failed on %s",
			full_fname(dest));
		errno = save_errno;
		return -1;
	}

#ifdef SUPPORT_XATTRS
	if (preserve_xattrs)
		copy_xattrs(source, dest);
#endif

	return 0;
}
コード例 #11
0
int
main(int argc, char * const argv[])
{
    Boolean			doDNS	= FALSE;
    Boolean			doNet	= FALSE;
    Boolean			doNWI	= FALSE;
    Boolean			doPrefs	= FALSE;
    Boolean			doProxy	= FALSE;
    Boolean			doReach	= FALSE;
    Boolean			doSnap	= FALSE;
    char			*get	= NULL;
    char			*log	= NULL;
    extern int		optind;
    int			opt;
    int			opti;
    const char		*prog	= argv[0];
    char			*renew	= NULL;
    char			*set	= NULL;
    char			*nc_cmd	= NULL;
    InputRef		src;
    int			timeout	= 15;	/* default timeout (in seconds) */
    char			*wait	= NULL;
    Boolean			watch	= FALSE;
    int			xStore	= 0;	/* non dynamic store command line options */

    /* process any arguments */

    while ((opt = getopt_long(argc, argv, "dDvprt:w:W", longopts, &opti)) != -1)
        switch(opt) {
        case 'd':
            _sc_debug = TRUE;
            _sc_log   = FALSE;	/* enable framework logging */
            break;
        case 'D':
            doDispatch = TRUE;
            break;
        case 'v':
            _sc_verbose = TRUE;
            _sc_log     = FALSE;	/* enable framework logging */
            break;
        case 'p':
            enablePrivateAPI = TRUE;
            break;
        case 'r':
            doReach = TRUE;
            xStore++;
            break;
        case 't':
            timeout = atoi(optarg);
            break;
        case 'w':
            wait = optarg;
            xStore++;
            break;
        case 'W':
            watch = TRUE;
            break;
        case 0:
            if        (strcmp(longopts[opti].name, "dns") == 0) {
                doDNS = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "get") == 0) {
                get = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "nc") == 0) {
                nc_cmd = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "net") == 0) {
                doNet = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "nwi") == 0) {
                doNWI = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "prefs") == 0) {
                doPrefs = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "proxy") == 0) {
                doProxy = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "renew") == 0) {
                renew = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "set") == 0) {
                set = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "snapshot") == 0) {
                doSnap = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "log") == 0) {
                log = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "user") == 0) {
                username = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            } else if (strcmp(longopts[opti].name, "password") == 0) {
                password = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            } else if (strcmp(longopts[opti].name, "secret") == 0) {
                sharedsecret = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            }
            break;
        case '?':
        default :
            usage(prog);
        }
    argc -= optind;
    argv += optind;

    if (xStore > 1) {
        // if we are attempting to process more than one type of request
        usage(prog);
    }

    /* are we checking (or watching) the reachability of a host/address */
    if (doReach) {
        if (argc < 1) {
            usage(prog);
        }
        if (watch) {
            do_watchReachability(argc, (char **)argv);
        } else {
            do_checkReachability(argc, (char **)argv);
        }
        /* NOT REACHED */
    }

    /* are we waiting on the presense of a dynamic store key */
    if (wait) {
        do_wait(wait, timeout);
        /* NOT REACHED */
    }

    /* are we looking up the DNS configuration */
    if (doDNS) {
        do_showDNSConfiguration(argc, (char **)argv);
        /* NOT REACHED */
    }

    if (doNWI) {
        do_nwi(argc, (char**)argv);
        /* NOT REACHED */
    }

    if (doSnap) {
        if (!enablePrivateAPI
#if	!TARGET_IPHONE_SIMULATOR
                || (geteuid() != 0)
#endif	// !TARGET_IPHONE_SIMULATOR
           ) {
            usage(prog);
        }

        do_open(0, NULL);	/* open the dynamic store */
        do_snapshot(argc, (char**)argv);
        exit(0);
    }

    /* are we looking up a preference value */
    if (get) {
        if (argc != 2) {
            if (findPref(get) < 0) {
                usage(prog);
            }
        } else {
            /* need to go back one argument
             * for the filename */
            argc++;
            argv--;
        }

        do_getPref(get, argc, (char **)argv);
        /* NOT REACHED */
    }

    /* are we looking up the proxy configuration */
    if (doProxy) {
        do_showProxyConfiguration(argc, (char **)argv);
        /* NOT REACHED */
    }

    /* are we changing a preference value */
    if (set) {
        if (findPref(set) < 0) {
            usage(prog);
        }
        do_setPref(set, argc, (char **)argv);
        /* NOT REACHED */
    }

    /* verbose log */
    if (log != NULL) {
        if (strcasecmp(log, "IPMonitor")) {
            usage(prog);
        }
        do_log(log, argc, (char * *)argv);
        /* NOT REACHED */
    }
    /* network connection commands */
    if (nc_cmd) {
        if (find_nc_cmd(nc_cmd) < 0) {
            usage(prog);
        }
        do_nc_cmd(nc_cmd, argc, (char **)argv, watch);
        /* NOT REACHED */
    }

    if (doNet) {
        /* if we are going to be managing the network configuration */
        commands  = (cmdInfo *)commands_net;
        nCommands = nCommands_net;

        if (!getenv("ENABLE_EXPERIMENTAL_SCUTIL_COMMANDS")) {
            usage(prog);
        }

        do_net_init();				/* initialization */
        do_net_open(argc, (char **)argv);	/* open prefs */
    } else if (doPrefs) {
        /* if we are going to be managing the network configuration */
        commands  = (cmdInfo *)commands_prefs;
        nCommands = nCommands_prefs;

        do_dictInit(0, NULL);			/* start with an empty dictionary */
        do_prefs_init();			/* initialization */
        do_prefs_open(argc, (char **)argv);	/* open prefs */
    } else {
        /* if we are going to be managing the dynamic store */
        commands  = (cmdInfo *)commands_store;
        nCommands = nCommands_store;

        do_dictInit(0, NULL);	/* start with an empty dictionary */
        do_open(0, NULL);	/* open the dynamic store */
    }

    /* are we trying to renew a DHCP lease */
    if (renew != NULL) {
        do_renew(renew);
        /* NOT REACHED */
    }

    /* allocate command input stream */
    src = (InputRef)CFAllocatorAllocate(NULL, sizeof(Input), 0);
    src->fp = stdin;
    src->el = NULL;
    src->h  = NULL;

    if (isatty(fileno(src->fp))) {
        int		editmode	= 1;
        HistEvent	ev;
        struct termios	t;

        if (tcgetattr(fileno(src->fp), &t) != -1) {
            if ((t.c_lflag & ECHO) == 0) {
                editmode = 0;
            }
        }
        src->el = el_init(prog, src->fp, stdout, stderr);
        src->h  = history_init();

        (void)history(src->h, &ev, H_SETSIZE, INT_MAX);
        el_set(src->el, EL_HIST, history, src->h);

        if (!editmode) {
            el_set(src->el, EL_EDITMODE, 0);
        }

        el_set(src->el, EL_EDITOR, "emacs");
        el_set(src->el, EL_PROMPT, prompt);

        el_source(src->el, NULL);

        if ((el_get(src->el, EL_EDITMODE, &editmode) != -1) && editmode != 0) {
            el_set(src->el, EL_SIGNAL, 1);
        } else {
            history_end(src->h);
            src->h = NULL;
            el_end(src->el);
            src->el = NULL;
        }
    }

    while (TRUE) {
        Boolean	ok;

        ok = process_line(src);
        if (!ok) {
            break;
        }
    }

    /* close the socket, free resources */
    if (src->h)	history_end(src->h);
    if (src->el)	el_end(src->el);
    (void)fclose(src->fp);
    CFAllocatorDeallocate(NULL, src);

    exit (EX_OK);	// insure the process exit status is 0
    return 0;	// ...and make main fit the ANSI spec.
}
コード例 #12
0
ファイル: IniFile.hpp プロジェクト: Fruneng/POI_DB
	bool open(const std::string & IniFileName)
	{
		return do_open(IniFileName);
	};
コード例 #13
0
ファイル: newFs2.c プロジェクト: joseignaciosg/SO--TP3-2011
int open(char *filename, int flags, int mode) {
	do_open(filename, flags, mode);
}
コード例 #14
0
ファイル: main.c プロジェクト: 14rcole/ostree
static int
callback_create(const char *path, mode_t mode, struct fuse_file_info *finfo)
{
  return do_open (path, mode, finfo);
}
コード例 #15
0
ファイル: chirp_tool.c プロジェクト: ailurus1991/cctools
int main(int argc, char *argv[])
{
	char *temp;
	int did_explicit_auth = 0;
	char *tickets = NULL;
	char prompt[CHIRP_LINE_MAX];
	char line[CHIRP_LINE_MAX];
	char **user_argv = 0;
	int user_argc;
	signed char c;
	int result = 0;

	debug_config(argv[0]);

	static struct option long_options[] = {
		{"auth", required_argument, 0, 'a'},
		{"debug", required_argument, 0, 'd'},
		{"tickets", required_argument, 0, 'i'},
		{"verbose", no_argument, 0, 'l'},
		{"timeout", required_argument, 0, 't'},
		{"version", no_argument, 0, 'v'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};

	while((c = getopt_long(argc, argv, "+a:d:hi:lt:v", long_options, NULL)) > -1) {
		switch (c) {
		case 'a':
			auth_register_byname(optarg);
			did_explicit_auth = 1;
			break;
		case 'd':
			debug_flags_set(optarg);
			break;
		case 'h':
			show_help(argv[0]);
			exit(0);
			break;
		case 'i':
			tickets = strdup(optarg);
			break;
		case 'l':
			long_information = 1;
			break;
		case 't':
			timeout = string_time_parse(optarg);
			break;
		case 'v':
			cctools_version_print(stdout, argv[0]);
			exit(0);
			break;
		}
	}

	cctools_version_debug(D_DEBUG, argv[0]);

	if(!did_explicit_auth)
		auth_register_all();
	if(tickets) {
		auth_ticket_load(tickets);
		free(tickets);
	} else if(getenv(CHIRP_CLIENT_TICKETS)) {
		auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS));
	} else {
		auth_ticket_load(NULL);
	}

	getcwd(current_local_dir, CHIRP_PATH_MAX);

	/* interactive mode if input is a TTY but we are not simply executing a
	 * command from argv */
	interactive_mode = isatty(0) && !((argc - optind) > 1);

	if(optind < argc) {
		stoptime = time(0) + timeout;
		if(do_open(1, &argv[optind - 1])) {
			fprintf(stderr, "couldn't open %s: %s\n", argv[optind], strerror(errno));
			return 1;
		}
	}

	if((argc - optind) > 1) {
		return !process_command(argc - optind - 1, &argv[optind + 1]);
	}

	while(1) {
		if(interactive_mode) {
			sprintf(prompt, " chirp:%s:%s> ", current_host, current_remote_dir);
		} else {
			prompt[0] = 0;
		}

#ifdef HAS_LIBREADLINE
		temp = readline(prompt);
		if(!temp)
			break;
		strcpy(line, temp);
		free(temp);
#else
		printf("%s", prompt);
		fflush(stdout);
		if(!fgets(line, CHIRP_LINE_MAX, stdin))
			break;
#endif

		if(!line[0])
			continue;

		if(!interactive_mode && (temp = strchr(line, '#'))) {	/* comment? */
			for(temp--; temp > line && isspace((int) *temp); temp--);	/* preceding space? */
			if(temp <= line)
				continue;	/* else not comment */
		}
#ifdef HAS_LIBREADLINE
		add_history(line);
#endif

		{
			char *start = line, *last = strlen(line) + line;
			while(*start != '\0') {	/* process compound commands */
				char *end = strchr(start, ';');
				while(end != NULL && end != start && *(end - 1) == '\\')
					end = strchr(end + 1, ';');
				if(end == NULL)
					end = start + strlen(start);
				*end = '\0';

				if(user_argv)
					free(user_argv);
				string_split(start, &user_argc, &user_argv);
				if(user_argc == 0) {
					start++;
					continue;
				}
				result = process_command(user_argc, user_argv);
				start = end == last ? last : end + 1;
			}
		}
		if(!interactive_mode && !result)
			break;
	}

	if(result) {
		return 0;
	} else {
		return 1;
	}
}
コード例 #16
0
ファイル: output.c プロジェクト: 00datman/ompi
/*
 * Reset the parameters on a stream
 */
int pmix_output_reopen(int output_id, pmix_output_stream_t * lds)
{
    return do_open(output_id, lds);
}
コード例 #17
0
void MainWindow::on_action_Open_triggered()
{
	do_open();
}
コード例 #18
0
ファイル: arp.c プロジェクト: Hooman3/minix
int main(int argc, char *argv[])
{
	int c;
	char *hostname, *ethername;
	int do_temp, do_pub;
	int a_flag, d_flag, n_flag, s_flag, S_flag;
	char *I_arg;

	(progname=strrchr(argv[0],'/')) ? progname++ : (progname=argv[0]);

	a_flag= d_flag= n_flag= s_flag= S_flag= 0;
	I_arg= NULL;
	while(c= getopt(argc, argv, "adnsS?I:"), c != -1)
	{
		switch(c)
		{
		case '?':	usage();
		case 'a':	a_flag= 1; break;
		case 'd':	d_flag= 1; break;
		case 'n':	n_flag= 1; break;
		case 's':	s_flag= 1; break;
		case 'S':	S_flag= 1; break;
		case 'I':	I_arg= optarg; break;
		default:	fatal("getopt failed: '%c'", c);
		}
	}

	hostname= NULL;		/* lint */
	ethername= NULL;	/* lint */
	do_temp= do_pub= 0;	/* lint */

	if (n_flag + d_flag + s_flag + S_flag > 1)
		usage();
	if (s_flag || S_flag)
	{
		if (optind >= argc) usage();
		hostname= argv[optind++];

		if (optind >= argc) usage();
		ethername= argv[optind++];

		do_temp= do_pub= 0;
		while (optind < argc) 
		{
			if (strcasecmp(argv[optind], "temp") == 0)
			{
				do_temp= 1;
				optind++;
				continue;
			}
			if (strcasecmp(argv[optind], "pub") == 0)
			{
				do_pub= 1;
				optind++;
				continue;
			}
			usage();
		}
	}
	else if (d_flag)
	{
		if (!a_flag)
		{
			if (optind >= argc)
				usage();
			hostname= argv[optind++];
			if (optind != argc)
				usage();
		}
	}
	else if (a_flag)
	{
		if (optind != argc)
			usage();
		do_setuid= 1;
	}
	else
	{
		if (optind >= argc)
			usage();
		hostname= argv[optind++];
		if (optind != argc)
			usage();
		do_setuid= 1;
	}

	do_open(I_arg);
	if (d_flag)
	{
		if (a_flag)
			delete_all();
		else
			delete(hostname);
	}
	else if (s_flag || S_flag)
		do_set(hostname, ethername, do_temp, do_pub, S_flag);
	else if (a_flag)
		show_all(n_flag);
	else
		show_one(hostname, n_flag);
	exit(0);
}
コード例 #19
0
ファイル: generator.c プロジェクト: drasch/rsync-inplace
/**
 * Acts on file number @p i from @p flist, whose name is @p fname.
 *
 * First fixes up permissions, then generates checksums for the file.
 *
 * @note This comment was added later by mbp who was trying to work it
 * out.  It might be wrong.
 **/ 
int recv_generator(char *fname, struct file_list *flist, int i, int f_out)
{  
	int fd;
	STRUCT_STAT st;
	struct map_struct *buf;
	struct sum_struct *s;
	int statret;
	struct file_struct *file = flist->files[i];
	struct timeval tv_start;
	char *fnamecmp;
	char fnamecmpbuf[MAXPATHLEN];
	extern char *compare_dest;
	extern int list_only;
	extern int preserve_perms;
	extern int only_existing;
	extern int orig_umask;

	if (list_only) return 0;

	if (verbose > 2)
		rprintf(FINFO,"recv_generator(%s,%d)\n",fname,i);

	statret = link_stat(fname,&st);

	if (only_existing && statret == -1 && errno == ENOENT) {
		/* we only want to update existing files */
		if (verbose > 1) rprintf(FINFO, "not creating new file \"%s\"\n",fname);
		return 0;
	}

	if (statret == 0 && 
	    !preserve_perms && 
	    (S_ISDIR(st.st_mode) == S_ISDIR(file->mode))) {
		/* if the file exists already and we aren't perserving
                   presmissions then act as though the remote end sent
                   us the file permissions we already have */
		file->mode = (file->mode & _S_IFMT) | (st.st_mode & ~_S_IFMT);
	}

	if (S_ISDIR(file->mode)) {
                /* The file to be received is a directory, so we need
                 * to prepare appropriately.  If there is already a
                 * file of that name and it is *not* a directory, then
                 * we need to delete it.  If it doesn't exist, then
                 * recursively create it. */
          
		if (dry_run) return 0; /* XXXX -- might cause inaccuracies?? -- mbp */
		if (statret == 0 && !S_ISDIR(st.st_mode)) {
			if (robust_unlink(fname) != 0) {
				rprintf(FERROR, RSYNC_NAME
					": recv_generator: unlink \"%s\" to make room for directory: %s\n",
                                        fname,strerror(errno));
				return 0;
			}
			statret = -1;
		}
		if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) {
			if (!(relative_paths && errno==ENOENT && 
			      create_directory_path(fname, orig_umask)==0 && 
			      do_mkdir(fname,file->mode)==0)) {
				rprintf(FERROR, RSYNC_NAME ": recv_generator: mkdir \"%s\": %s (2)\n",
					fname,strerror(errno));
			}
		}
		/* f_out is set to -1 when doing final directory 
		   permission and modification time repair */
		if (set_perms(fname,file,NULL,0) && verbose && (f_out != -1)) 
			rprintf(FINFO,"%s/\n",fname);
		return 0;
	}

	if (preserve_links && S_ISLNK(file->mode)) {
#if SUPPORT_LINKS
		char lnk[MAXPATHLEN];
		int l;
		extern int safe_symlinks;

		if (safe_symlinks && unsafe_symlink(file->link, fname)) {
			if (verbose) {
				rprintf(FINFO,"ignoring unsafe symlink \"%s\" -> \"%s\"\n",
					fname,file->link);
			}
			return 0;
		}
		if (statret == 0) {
			l = readlink(fname,lnk,MAXPATHLEN-1);
			if (l > 0) {
				lnk[l] = 0;
				/* A link already pointing to the
				 * right place -- no further action
				 * required. */
				if (strcmp(lnk,file->link) == 0) {
					set_perms(fname,file,&st,1);
					return 0;
				}
			}  
			/* Not a symlink, so delete whatever's
			 * already there and put a new symlink
			 * in place. */			   
			delete_file(fname);
		}
		if (do_symlink(file->link,fname) != 0) {
			rprintf(FERROR,RSYNC_NAME": symlink \"%s\" -> \"%s\": %s\n",
				fname,file->link,strerror(errno));
		} else {
			set_perms(fname,file,NULL,0);
			if (verbose) {
				rprintf(FINFO,"%s -> %s\n", fname,file->link);
			}
		}
#endif
		return 0;
	}

#ifdef HAVE_MKNOD
	if (am_root && preserve_devices && IS_DEVICE(file->mode)) {
		if (statret != 0 || 
		    st.st_mode != file->mode ||
		    st.st_rdev != file->rdev) {	
			delete_file(fname);
			if (verbose > 2)
				rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
					fname,(int)file->mode,(int)file->rdev);
			if (do_mknod(fname,file->mode,file->rdev) != 0) {
				rprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
			} else {
				set_perms(fname,file,NULL,0);
				if (verbose)
					rprintf(FINFO,"%s\n",fname);
			}
		} else {
			set_perms(fname,file,&st,1);
		}
		return 0;
	}
#endif

	if (preserve_hard_links && check_hard_link(file)) {
		if (verbose > 1)
			rprintf(FINFO, "recv_generator: \"%s\" is a hard link\n",f_name(file));
		return 0;
	}

	if (!S_ISREG(file->mode)) {
		rprintf(FINFO, "skipping non-regular file \"%s\"\n",fname);
		return 0;
	}

	fnamecmp = fname;

	if ((statret == -1) && (compare_dest != NULL)) {
		/* try the file at compare_dest instead */
		int saveerrno = errno;
		snprintf(fnamecmpbuf,MAXPATHLEN,"%s/%s",compare_dest,fname);
		statret = link_stat(fnamecmpbuf,&st);
		if (!S_ISREG(st.st_mode))
			statret = -1;
		if (statret == -1)
			errno = saveerrno;
		else
			fnamecmp = fnamecmpbuf;
	}

	if (statret == -1) {
		if (errno == ENOENT) {
			write_int(f_out,i);
			if (!dry_run) {
			    if(do_stats){
				gettimeofday(&tv_start,0);
				rprintf(FINFO, "File start: %s time: %d %d\n",fnamecmp,
				    tv_start.tv_sec,
				    tv_start.tv_usec);
			    }
			    send_sums(NULL,f_out);
			return 1;
			}
		} else {
			if (verbose > 1)
				rprintf(FERROR, RSYNC_NAME
					": recv_generator failed to open \"%s\": %s\n",
					fname, strerror(errno));
			return 0;
		}
	}

	if (!S_ISREG(st.st_mode)) {
		if (delete_file(fname) != 0) {
			return 0;
		}
		if(do_stats){
		    gettimeofday(&tv_start,0);
		    rprintf(FINFO, "File start: %s time: %d %d\n",fnamecmp,
			tv_start.tv_sec,
			tv_start.tv_usec);
		}

		/* now pretend the file didn't exist */
		write_int(f_out,i);
		if (!dry_run) send_sums(NULL,f_out);    
		return 1;
	}

	if (opt_ignore_existing && fnamecmp == fname) { 
		if (verbose > 1)
			rprintf(FINFO,"%s exists\n",fname);
		return 0;
	} 

	if (update_only && cmp_modtime(st.st_mtime,file->modtime)>0 && fnamecmp == fname) {
		if (verbose > 1)
			rprintf(FINFO,"%s is newer\n",fname);
		return 0;
	}

	if (skip_file(fname, file, &st)) {
		if (fnamecmp == fname)
			set_perms(fname,file,&st,1);
		return 0;
	}

	if (dry_run) {
		if(do_stats){
		    gettimeofday(&tv_start,0);
		    rprintf(FINFO, "File start: %s time: %d %d\n",fnamecmp,
			tv_start.tv_sec,
			tv_start.tv_usec);
		}
		write_int(f_out,i);
		return 1;
	}

	if (disable_deltas_p()) {
		if(do_stats){
		    gettimeofday(&tv_start,0);
		    rprintf(FINFO, "File start: %s time: %d %d\n",fnamecmp,
			tv_start.tv_sec,
			tv_start.tv_usec);
		}
		write_int(f_out,i);
		send_sums(NULL,f_out);    
		return 1;
	}
	if(do_stats){
	    gettimeofday(&tv_start,0);
	    rprintf(FINFO, "File start: %s time: %d %d\n",fnamecmp,
		    tv_start.tv_sec,
		    tv_start.tv_usec);
	}
	/* open the file */  
	fd = do_open(fnamecmp, O_RDONLY, 0);

	if (fd == -1) {
		rprintf(FERROR,RSYNC_NAME": failed to open \"%s\", continuing : %s\n",fnamecmp,strerror(errno));
		/* pretend the file didn't exist */
		write_int(f_out,i);
		send_sums(NULL,f_out);
		return 1;
	}

	if (st.st_size > 0) {
		buf = map_file(fd,st.st_size);
	} else {
		buf = NULL;
	}

	if (verbose > 3)
		rprintf(FINFO,"gen mapped %s of size %.0f\n",fnamecmp,(double)st.st_size);

	if(do_stats){
	    timing(TIMING_START);
	}
	s = generate_sums(buf,st.st_size,adapt_block_size(file, block_size));

	if(do_stats){
	    rprintf(FINFO, "Generator: %s %s\n", fnamecmp,timing(TIMING_END));
	}

	if (verbose > 2)
		rprintf(FINFO,"sending sums for %d\n",i);

	write_int(f_out,i);
	if(do_stats){
	    timing(TIMING_START);
	}
	send_sums(s,f_out);

	if(do_stats){
	    rprintf(FINFO, "Send sums: %s %s\n", fnamecmp,timing(TIMING_END));
	}
	close(fd);
	if (buf) unmap_file(buf);

	free_sums(s);
	return 1;
}
コード例 #20
0
static int process_requests(int sock)
{
    int flags;
    int size = 0;
    int retval = 0;
    uint64_t offset;
    ProxyHeader header;
    int mode, uid, gid;
    V9fsString name, value;
    struct timespec spec[2];
    V9fsString oldpath, path;
    struct iovec in_iovec, out_iovec;

    in_iovec.iov_base  = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
    in_iovec.iov_len   = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;
    out_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
    out_iovec.iov_len  = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;

    while (1) {
        /*
         * initialize the header type, so that we send
         * response to proper request type.
         */
        header.type = 0;
        retval = read_request(sock, &in_iovec, &header);
        if (retval < 0) {
            goto err_out;
        }

        switch (header.type) {
        case T_OPEN:
            retval = do_open(&in_iovec);
            break;
        case T_CREATE:
            retval = do_create(&in_iovec);
            break;
        case T_MKNOD:
        case T_MKDIR:
        case T_SYMLINK:
            retval = do_create_others(header.type, &in_iovec);
            break;
        case T_LINK:
            v9fs_string_init(&path);
            v9fs_string_init(&oldpath);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ,
                                     "ss", &oldpath, &path);
            if (retval > 0) {
                retval = link(oldpath.data, path.data);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&oldpath);
            v9fs_string_free(&path);
            break;
        case T_LSTAT:
        case T_STATFS:
            retval = do_stat(header.type, &in_iovec, &out_iovec);
            break;
        case T_READLINK:
            retval = do_readlink(&in_iovec, &out_iovec);
            break;
        case T_CHMOD:
            v9fs_string_init(&path);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ,
                                     "sd", &path, &mode);
            if (retval > 0) {
                retval = chmod(path.data, mode);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            break;
        case T_CHOWN:
            v9fs_string_init(&path);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sdd", &path,
                                     &uid, &gid);
            if (retval > 0) {
                retval = lchown(path.data, uid, gid);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            break;
        case T_TRUNCATE:
            v9fs_string_init(&path);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sq",
                                     &path, &offset);
            if (retval > 0) {
                retval = truncate(path.data, offset);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            break;
        case T_UTIME:
            v9fs_string_init(&path);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sqqqq", &path,
                                     &spec[0].tv_sec, &spec[0].tv_nsec,
                                     &spec[1].tv_sec, &spec[1].tv_nsec);
            if (retval > 0) {
                retval = qemu_utimens(path.data, spec);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            break;
        case T_RENAME:
            v9fs_string_init(&path);
            v9fs_string_init(&oldpath);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ,
                                     "ss", &oldpath, &path);
            if (retval > 0) {
                retval = rename(oldpath.data, path.data);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&oldpath);
            v9fs_string_free(&path);
            break;
        case T_REMOVE:
            v9fs_string_init(&path);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "s", &path);
            if (retval > 0) {
                retval = remove(path.data);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            break;
        case T_LGETXATTR:
        case T_LLISTXATTR:
            retval = do_getxattr(header.type, &in_iovec, &out_iovec);
            break;
        case T_LSETXATTR:
            v9fs_string_init(&path);
            v9fs_string_init(&name);
            v9fs_string_init(&value);
            retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sssdd", &path,
                                     &name, &value, &size, &flags);
            if (retval > 0) {
                retval = lsetxattr(path.data,
                                   name.data, value.data, size, flags);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            v9fs_string_free(&name);
            v9fs_string_free(&value);
            break;
        case T_LREMOVEXATTR:
            v9fs_string_init(&path);
            v9fs_string_init(&name);
            retval = proxy_unmarshal(&in_iovec,
                                     PROXY_HDR_SZ, "ss", &path, &name);
            if (retval > 0) {
                retval = lremovexattr(path.data, name.data);
                if (retval < 0) {
                    retval = -errno;
                }
            }
            v9fs_string_free(&path);
            v9fs_string_free(&name);
            break;
        case T_GETVERSION:
            retval = do_getversion(&in_iovec, &out_iovec);
            break;
        default:
            goto err_out;
            break;
        }

        if (process_reply(sock, header.type, &out_iovec, retval) < 0) {
            goto err_out;
        }
    }
err_out:
    g_free(in_iovec.iov_base);
    g_free(out_iovec.iov_base);
    return -1;
}
コード例 #21
0
ファイル: util.c プロジェクト: cofyc/rsync
/* Copy a file.  If ofd < 0, copy_file unlinks and opens the "dest" file.
 * Otherwise, it just writes to and closes the provided file descriptor.
 * In either case, if --xattrs are being preserved, the dest file will
 * have its xattrs set from the source file.
 *
 * This is used in conjunction with the --temp-dir, --backup, and
 * --copy-dest options. */
int copy_file(const char *source, const char *dest, int ofd, mode_t mode)
{
	int ifd;
	char buf[1024 * 8];
	int len;   /* Number of bytes read into `buf'. */
#ifdef PREALLOCATE_NEEDS_TRUNCATE
	OFF_T preallocated_len = 0, offset = 0;
#endif

	if ((ifd = do_open(source, O_RDONLY, 0)) < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "open %s", full_fname(source));
		errno = save_errno;
		return -1;
	}

	if (ofd < 0) {
		if (robust_unlink(dest) && errno != ENOENT) {
			int save_errno = errno;
			rsyserr(FERROR_XFER, errno, "unlink %s", full_fname(dest));
			errno = save_errno;
			return -1;
		}

#ifdef SUPPORT_XATTRS
		if (preserve_xattrs)
			mode |= S_IWUSR;
#endif
		mode &= INITACCESSPERMS;
		if ((ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0) {
			int save_errno = errno;
			rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(dest));
			close(ifd);
			errno = save_errno;
			return -1;
		}
	}

#ifdef SUPPORT_PREALLOCATION
	if (preallocate_files) {
		STRUCT_STAT srcst;

		/* Try to preallocate enough space for file's eventual length.  Can
		 * reduce fragmentation on filesystems like ext4, xfs, and NTFS. */
		if (do_fstat(ifd, &srcst) < 0)
			rsyserr(FWARNING, errno, "fstat %s", full_fname(source));
		else if (srcst.st_size > 0) {
			if (do_fallocate(ofd, 0, srcst.st_size) == 0) {
#ifdef PREALLOCATE_NEEDS_TRUNCATE
				preallocated_len = srcst.st_size;
#endif
			} else
				rsyserr(FWARNING, errno, "do_fallocate %s", full_fname(dest));
		}
	}
#endif

	while ((len = safe_read(ifd, buf, sizeof buf)) > 0) {
		if (full_write(ofd, buf, len) < 0) {
			int save_errno = errno;
			rsyserr(FERROR_XFER, errno, "write %s", full_fname(dest));
			close(ifd);
			close(ofd);
			errno = save_errno;
			return -1;
		}
#ifdef PREALLOCATE_NEEDS_TRUNCATE
		offset += len;
#endif
	}

	if (len < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "read %s", full_fname(source));
		close(ifd);
		close(ofd);
		errno = save_errno;
		return -1;
	}

	if (close(ifd) < 0) {
		rsyserr(FWARNING, errno, "close failed on %s",
			full_fname(source));
	}

#ifdef PREALLOCATE_NEEDS_TRUNCATE
	/* Source file might have shrunk since we fstatted it.
	 * Cut off any extra preallocated zeros from dest file. */
	if (offset < preallocated_len && do_ftruncate(ofd, offset) < 0) {
		/* If we fail to truncate, the dest file may be wrong, so we
		 * must trigger the "partial transfer" error. */
		rsyserr(FERROR_XFER, errno, "ftruncate %s", full_fname(dest));
	}
#endif

	if (close(ofd) < 0) {
		int save_errno = errno;
		rsyserr(FERROR_XFER, errno, "close failed on %s",
			full_fname(dest));
		errno = save_errno;
		return -1;
	}

#ifdef SUPPORT_XATTRS
	if (preserve_xattrs)
		copy_xattrs(source, dest);
#endif

	return 0;
}
コード例 #22
0
ファイル: mysql_db.cpp プロジェクト: ly20119/mooon
void CMySQLConnection::open() throw (CDBException)
{    
    _id = utils::CStringUtils::format_string("mysql://%s@%s:%d", _db_name.c_str(), _db_ip.c_str(), _db_port);
    do_open();
}
コード例 #23
0
/*
 * Same as file_absolute_open(), no open() error logged.
 */
int
file_absolute_open_silent(const char *path, int flags, int mode)
{
	return do_open(path, flags, mode, FALSE, TRUE, TRUE);
}
コード例 #24
0
ファイル: mysql_db.cpp プロジェクト: ly20119/mooon
void CMySQLConnection::reopen() throw (CDBException)
{
    // 先关闭释放资源,才能再建立
    close();
    do_open();
}
コード例 #25
0
/**
 * Same as file_open_missing(), no error logging.
 */
int
file_open_missing_silent(const char *path, int flags)
{
	return do_open(path, flags, 0, TRUE, TRUE, TRUE);
}
コード例 #26
0
ファイル: elf32.c プロジェクト: Aliced3645/os
static int _elf32_load(const char *filename, int fd, char *const argv[],
                       char *const envp[], uint32_t *eip, uint32_t *esp)
{
        int err = 0;
        Elf32_Ehdr header;
        Elf32_Ehdr interpheader;

        /* variables to clean up on failure */
        vmmap_t *map = NULL;
        file_t *file = NULL;
        char *pht = NULL;
        char *interpname = NULL;
        int interpfd = -1;
        file_t *interpfile = NULL;
        char *interppht = NULL;
        Elf32_auxv_t *auxv = NULL;
        char *argbuf = NULL;

        uintptr_t entry;

        file = fget(fd);
        KASSERT(NULL != file);

        /* Load and verify the ELF header */
        if (0 > (err = _elf32_load_ehdr(fd, &header, 0))) {
                goto done;
        }

        if (NULL == (map = vmmap_create())) {
                err = -ENOMEM;
                goto done;
        }

        size_t phtsize = header.e_phentsize * header.e_phnum;
        if (NULL == (pht = kmalloc(phtsize))) {
                err = -ENOMEM;
                goto done;
        }
        /* Read in the program header table */
        if (0 > (err = _elf32_load_phtable(fd, &header, pht, phtsize))) {
                goto done;
        }
        /* Load the segments in the program header table */
        if (0 > (err = _elf32_map_progsegs(file->f_vnode, map, &header, pht, 0))) {
                goto done;
        }

        Elf32_Phdr *phinterp = NULL;
        /* Check if program requires an interpreter */
        if (0 > (err = _elf32_find_phinterp(&header, pht, &phinterp))) {
                goto done;
        }

        /* Calculate program bounds for future reference */
        void *proglow;
        void *proghigh;
        _elf32_calc_progbounds(&header, pht, &proglow, &proghigh);

        entry = (uintptr_t) header.e_entry;

        /* if an interpreter was requested load it */
        if (NULL != phinterp) {
                /* read the file name of the interpreter from the binary */
                if (0 > (err = do_lseek(fd, phinterp->p_offset, SEEK_SET))) {
                        goto done;
                } else if (NULL == (interpname = kmalloc(phinterp->p_filesz))) {
                        err = -ENOMEM;
                        goto done;
                } else if (0 > (err = do_read(fd, interpname, phinterp->p_filesz))) {
                        goto done;
                }
                if (err != (int)phinterp->p_filesz) {
                        err = -ENOEXEC;
                        goto done;
                }

                /* open the interpreter */
                dbgq(DBG_ELF, "ELF Interpreter: %*s\n", phinterp->p_filesz, interpname);
                if (0 > (interpfd = do_open(interpname, O_RDONLY))) {
                        err = interpfd;
                        goto done;
                }
                kfree(interpname);
                interpname = NULL;

                interpfile = fget(interpfd);
                KASSERT(NULL != interpfile);

                /* Load and verify the interpreter ELF header */
                if (0 > (err = _elf32_load_ehdr(interpfd, &interpheader, 1))) {
                        goto done;
                }
                size_t interpphtsize = interpheader.e_phentsize * interpheader.e_phnum;
                if (NULL == (interppht = kmalloc(interpphtsize))) {
                        err = -ENOMEM;
                        goto done;
                }
                /* Read in the program header table */
                if (0 > (err = _elf32_load_phtable(interpfd, &interpheader, interppht, interpphtsize))) {
                        goto done;
                }

                /* Interpreter shouldn't itself need an interpreter */
                Elf32_Phdr *interpphinterp;
                if (0 > (err = _elf32_find_phinterp(&interpheader, interppht, &interpphinterp))) {
                        goto done;
                }
                if (NULL != interpphinterp) {
                        err = -EINVAL;
                        goto done;
                }

                /* Calculate the interpreter program size */
                void *interplow;
                void *interphigh;
                _elf32_calc_progbounds(&interpheader, interppht, &interplow, &interphigh);
                uint32_t interpnpages = ADDR_TO_PN(PAGE_ALIGN_UP(interphigh)) - ADDR_TO_PN(interplow);

                /* Find space for the interpreter */
                /* This is the first pn at which the interpreter will be mapped */
                uint32_t interppagebase = (uint32_t) vmmap_find_range(map, interpnpages, VMMAP_DIR_HILO);
                if ((uint32_t) - 1 == interppagebase) {
                        err = -ENOMEM;
                        goto done;
                }

                /* Base address at which the interpreter begins on that page */
                void *interpbase = (void *)((uintptr_t)PN_TO_ADDR(interppagebase) + PAGE_OFFSET(interplow));

                /* Offset from "expected base" in number of pages */
                int32_t interpoff = (int32_t) interppagebase - (int32_t) ADDR_TO_PN(interplow);

                entry = (uintptr_t) interpbase + ((uintptr_t) interpheader.e_entry - (uintptr_t) interplow);

                /* Load the interpreter program header and map in its segments */
                if (0 > (err = _elf32_map_progsegs(interpfile->f_vnode, map, &interpheader, interppht, interpoff))) {
                        goto done;
                }

                /* Build the ELF aux table */
                /* Need to hold AT_PHDR, AT_PHENT, AT_PHNUM, AT_ENTRY, AT_BASE,
                 * AT_PAGESZ, AT_NULL */
                if (NULL == (auxv = (Elf32_auxv_t *) kmalloc(7 * sizeof(Elf32_auxv_t)))) {
                        err = -ENOMEM;
                        goto done;
                }
                Elf32_auxv_t *auxvent = auxv;

                /* Add all the necessary entries */
                auxvent->a_type = AT_PHDR;
                auxvent->a_un.a_ptr = pht;
                auxvent++;

                auxvent->a_type = AT_PHENT;
                auxvent->a_un.a_val = header.e_phentsize;
                auxvent++;

                auxvent->a_type = AT_PHNUM;
                auxvent->a_un.a_val = header.e_phnum;
                auxvent++;

                auxvent->a_type = AT_ENTRY;
                auxvent->a_un.a_ptr = (void *) header.e_entry;
                auxvent++;

                auxvent->a_type = AT_BASE;
                auxvent->a_un.a_ptr = interpbase;
                auxvent++;

                auxvent->a_type = AT_PAGESZ;
                auxvent->a_un.a_val = PAGE_SIZE;
                auxvent++;

                auxvent->a_type = AT_NULL;

        } else {
                /* Just put AT_NULL (we don't really need this at all) */
                if (NULL == (auxv = (Elf32_auxv_t *) kmalloc(sizeof(Elf32_auxv_t)))) {
                        err = -ENOMEM;
                        goto done;
                }
                auxv->a_type = AT_NULL;
        }

        /* Allocate a stack. We put the stack immediately below the program text.
         * (in the Intel x86 ELF supplement pp 59 "example stack", that is where the
         * stack is located). I suppose we can add this "extra page for magic data" too */
        uint32_t stack_lopage = ADDR_TO_PN(proglow) - (DEFAULT_STACK_SIZE / PAGE_SIZE) - 1;
        err = vmmap_map(map, NULL, stack_lopage, (DEFAULT_STACK_SIZE / PAGE_SIZE) + 1,
                        PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, 0, 0, NULL);
        KASSERT(0 == err);
        dbg(DBG_ELF, "Mapped stack at low addr 0x%p, size %#x\n",
            PN_TO_ADDR(stack_lopage), DEFAULT_STACK_SIZE + PAGE_SIZE);


        /* Copy out arguments onto the user stack */
        int argc, envc, auxc;
        size_t argsize = _elf32_calc_argsize(argv, envp, auxv, phtsize, &argc, &envc, &auxc);
        /* Make sure it fits on the stack */
        if (argsize >= DEFAULT_STACK_SIZE) {
                err = -E2BIG;
                goto done;
        }
        /* Copy arguments into kernel buffer */
        if (NULL == (argbuf = (char *) kmalloc(argsize))) {
                err = -ENOMEM;
                goto done;
        }
        /* Calculate where in user space we start putting the args. */
        void *arglow = (void *)((uintptr_t)(((char *) proglow) - argsize) & ~PTR_MASK);
        /* Copy everything into the user address space, modifying addresses in
         * argv, envp, and auxv to be user addresses as we go. */
        _elf32_load_args(map, arglow, argsize, argbuf, argv, envp, auxv, argc, envc, auxc, phtsize);

        dbg(DBG_ELF, "Past the point of no return. Swapping to map at 0x%p, setting brk to 0x%p\n", map, proghigh);
        /* the final threshold / What warm unspoken secrets will we learn? / Beyond
         * the point of no return ... */

        /* Give the process the new mappings. */
        vmmap_t *tempmap = curproc->p_vmmap;
        curproc->p_vmmap = map;
        map = tempmap; /* So the old maps are cleaned up */
        curproc->p_vmmap->vmm_proc = curproc;
        map->vmm_proc = NULL;

        /* Flush the process pagetables and TLB */
        pt_unmap_range(curproc->p_pagedir, USER_MEM_LOW, USER_MEM_HIGH);
        tlb_flush_all();

        /* Set the process break and starting break (immediately after the mapped-in
         * text/data/bss from the executable) */
        curproc->p_brk = proghigh;
        curproc->p_start_brk = proghigh;

        strncpy(curproc->p_comm, filename, PROC_NAME_LEN);

        /* Tell the caller the correct stack pointer and instruction
         * pointer to begin execution in user space */
        *eip = (uint32_t) entry;
        *esp = ((uint32_t) arglow) - 4; /* Space on the user stack for the (garbage) return address */
        /* Note that the return address will be fixed by the userland entry code,
         * whether in static or dynamic */

        /* And we're done */
        err = 0;

done:
        if (NULL != map) {
                vmmap_destroy(map);
        }
        if (NULL != file) {
                fput(file);
        }
        if (NULL != pht) {
                kfree(pht);
        }
        if (NULL != interpname) {
                kfree(interpname);
        }
        if (0 <= interpfd) {
                do_close(interpfd);
        }
        if (NULL != interpfile) {
                fput(interpfile);
        }
        if (NULL != interppht) {
                kfree(interppht);
        }
        if (NULL != auxv) {
                kfree(auxv);
        }
        if (NULL != argbuf) {
                kfree(argbuf);
        }
        return err;
}
コード例 #27
0
ファイル: output.c プロジェクト: anandhis/ompi
/*
 * Open a stream
 */
int opal_output_open(opal_output_stream_t * lds)
{
    return do_open(-1, lds);
}
コード例 #28
0
ファイル: special.c プロジェクト: bkero/Smaug
bool spec_mayor( CHAR_DATA *ch )
{
    static const char open_path[] =
	"W3a3003b33000c111d0d111Oe333333Oe22c222112212111a1S.";

    static const char close_path[] =
	"W3a3003b33000c111d0d111CE333333CE22c222112212111a1S.";

    static const char *path;
    static int pos;
    static bool move;

    if ( !move )
    {
	if ( time_info.hour ==  6 )
	{
	    path = open_path;
	    move = TRUE;
	    pos  = 0;
	}

	if ( time_info.hour == 20 )
	{
	    path = close_path;
	    move = TRUE;
	    pos  = 0;
	}
    }

    if ( ch->fighting )
	return spec_cast_cleric( ch );
    if ( !move || ch->position < POS_SLEEPING )
	return FALSE;

    switch ( path[pos] )
    {
    case '0':
    case '1':
    case '2':
    case '3':
	move_char( ch, get_exit( ch->in_room, path[pos] - '0' ), 0 );
	break;

    case 'W':
	ch->position = POS_STANDING;
    act( AT_ACTION, "$n awakens and groans loudly.", ch, NULL, NULL, TO_ROOM );
	break;

    case 'S':
	ch->position = POS_SLEEPING;
    act( AT_ACTION, "$n lies down and falls asleep.", ch, NULL, NULL, TO_ROOM );
	break;

    case 'a':
    act( AT_SAY, "$n says 'Hello Honey!'", ch, NULL, NULL, TO_ROOM );
	break;

    case 'b':
    act( AT_SAY, "$n says 'What a view!  I must do something about that dump!'",
	    ch, NULL, NULL, TO_ROOM );
	break;

    case 'c':
    act( AT_SAY, "$n says 'Vandals!  Youngsters have no respect for anything!'",
	    ch, NULL, NULL, TO_ROOM );
	break;

    case 'd':
    act( AT_SAY, "$n says 'Good day, citizens!'", ch, NULL, NULL, TO_ROOM );
	break;

    case 'e':
    act( AT_SAY, "$n says 'I hereby declare the town of Darkhaven open!'",
	    ch, NULL, NULL, TO_ROOM );
	break;

    case 'E':
    act( AT_SAY, "$n says 'I hereby declare the town of Darkhaven closed!'",
	    ch, NULL, NULL, TO_ROOM );
	break;

    case 'O':
	do_unlock( ch, "gate" );
	do_open( ch, "gate" );
	break;

    case 'C':
	do_close( ch, "gate" );
	do_lock( ch, "gate" );
	break;

    case '.' :
	move = FALSE;
	break;
    }

    pos++;
    return FALSE;
}
コード例 #29
0
ファイル: engine.cpp プロジェクト: scrooloose/hansolo
bool Engine::handle_keypress(int key) {
    bool turn_taken = true;
    switch(key) {
        case KEY_LEFT:
            player->move_left();
            break;
        case KEY_RIGHT:
            player->move_right();
            break;
        case KEY_UP:
            player->move_up();
            break;
        case KEY_DOWN:
            player->move_down();
            break;
        case KEY_C1:
        case KEY_END:
            player->move_down_left();
            break;
        case KEY_C3:
        case KEY_NPAGE:
            player->move_down_right();
            break;
        case KEY_A1:
        case KEY_HOME:
            player->move_up_left();
            break;
        case KEY_A3:
        case KEY_PPAGE:
            player->move_up_right();
            break;
        case (int)'f':
            state = FIRE;
            turn_taken = false;
            break;
        case (int)'i':
            state = VIEW_INVENTORY;
            turn_taken = false;
            break;
        case (int)'u':
            state = USE;
            turn_taken = false;
            break;
        case (int)'o':
            do_open();
            break;
        case (int)'.': // fall through to '>'
        case (int)'>':
            if (player->move_downstairs()) {
                if (map_list->has_next_map()) {
                    start_next_level();
                }else{
                    game_over_won();
                }
            }
            break;
        case (int)'w':
            state = WIELD;
            turn_taken = false;
            break;

        case (int)'q':
            main_loop_done = true;
            turn_taken = true;
            break;

        default:
            turn_taken = false;
    }
    return turn_taken;
}
コード例 #30
0
int main(int argc, char *argv[])
{
	long fd;
	int i, j, k;
	int bwloops;
	char *fname;
	char data[8192];
	int runtime;
	struct stat buf;
	struct timeval start, stop;
	stoptime = time(0) + 3600;
	int filesize = 16 * 1024 * 1024;

	if(argc != 6) {
		printf("use: %s <host> <file> <loops> <cycles> <bwloops>\n", argv[0]);
		return -1;
	}

	auth_register_all();

	host = argv[1];
	fname = argv[2];
	loops = atoi(argv[3]);
	cycles = atoi(argv[4]);
	bwloops = atoi(argv[5]);

	if(!strcmp(host, "unix")) {
		do_chirp = 0;
	} else {
		do_chirp = 1;
	}

#ifdef SYS_getpid
	RUN_LOOP("getpid", syscall(SYS_getpid));
#else
	RUN_LOOP("getpid", getpid());
#endif

	fd = do_open(fname, O_WRONLY | O_CREAT | O_TRUNC | do_sync, 0777);
	if(fd < 0 || fd == 0) {
		perror(fname);
		return -1;
	}

	RUN_LOOP("write1", do_pwrite(fd, data, 1, 0));
	RUN_LOOP("write8", do_pwrite(fd, data, 8192, 0));

	do_close(fd);

	fd = do_open(fname, O_RDONLY | do_sync, 0777);
	if(fd < 0) {
		perror(fname);
		return -1;
	}

	RUN_LOOP("read1", do_pread(fd, data, 1, 0));
	RUN_LOOP("read8", do_pread(fd, data, 8192, 0));

	do_close(fd);

	RUN_LOOP("stat", do_stat(fname, &buf));
	RUN_LOOP("open", fd = do_open(fname, O_RDONLY | do_sync, 0777); do_close(fd););