本文整理汇总了C++中setprogname函数的典型用法代码示例。如果您正苦于以下问题:C++ setprogname函数的具体用法?C++ setprogname怎么用?C++ setprogname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setprogname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main_ln
static int
main_ln(rtems_shell_ln_globals* globals, int argc, char *argv[])
{
struct stat sb;
int ch, exitval;
char *sourcedir;
struct getopt_data getopt_reent;
memset(&getopt_reent, 0, sizeof(getopt_data));
#if RTEMS_REMOVED
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
#endif
while ((ch = getopt_r(argc, argv, "fhinsv", &getopt_reent)) != -1)
switch (ch) {
case 'f':
fflag = 1;
iflag = 0;
break;
case 'h':
case 'n':
hflag = 1;
break;
case 'i':
iflag = 1;
fflag = 0;
break;
case 's':
sflag = 1;
break;
case 'v':
vflag = 1;
break;
case '?':
default:
usage(globals);
/* NOTREACHED */
}
argv += getopt_reent.optind;
argc -= getopt_reent.optind;
if (sflag) {
linkf = symlink;
linkch = '-';
} else {
linkf = link;
linkch = '=';
}
switch(argc) {
case 0:
usage(globals);
/* NOTREACHED */
case 1: /* ln target */
exit(linkit(globals, argv[0], ".", 1));
/* NOTREACHED */
case 2: /* ln target source */
exit(linkit(globals, argv[0], argv[1], 0));
/* NOTREACHED */
}
/* ln target1 target2 directory */
sourcedir = argv[argc - 1];
if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
/* we were asked not to follow symlinks, but found one at
the target--simulate "not a directory" error */
errno = ENOTDIR;
err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
/* NOTREACHED */
}
if (stat(sourcedir, &sb)) {
err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
/* NOTREACHED */
}
if (!S_ISDIR(sb.st_mode)) {
usage(globals);
/* NOTREACHED */
}
for (exitval = 0; *argv != sourcedir; ++argv)
exitval |= linkit(globals, *argv, sourcedir, 1);
exit(exitval);
/* NOTREACHED */
return 0;
}
示例2: main
int
main(int argc, char **argv)
{
krb5_error_code ret;
krb5_context context;
krb5_kdc_configuration *config;
krb5_storage *sp;
int fd, optidx = 0;
setprogname(argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag){
print_version(NULL);
exit(0);
}
ret = krb5_init_context(&context);
if (ret)
errx (1, "krb5_init_context failed to parse configuration file");
ret = krb5_kdc_get_config(context, &config);
if (ret)
krb5_err(context, 1, ret, "krb5_kdc_default_config");
kdc_openlog(context, "kdc-replay", config);
ret = krb5_kdc_set_dbinfo(context, config);
if (ret)
krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
#ifdef PKINIT
if (config->enable_pkinit) {
if (config->pkinit_kdc_identity == NULL)
krb5_errx(context, 1, "pkinit enabled but no identity");
if (config->pkinit_kdc_anchors == NULL)
krb5_errx(context, 1, "pkinit enabled but no X509 anchors");
krb5_kdc_pk_initialize(context, config,
config->pkinit_kdc_identity,
config->pkinit_kdc_anchors,
config->pkinit_kdc_cert_pool,
config->pkinit_kdc_revoke);
}
#endif /* PKINIT */
if (argc != 2)
errx(1, "argc != 2");
printf("kdc replay\n");
fd = open(argv[1], O_RDONLY);
if (fd < 0)
err(1, "open: %s", argv[1]);
sp = krb5_storage_from_fd(fd);
if (sp == NULL)
krb5_errx(context, 1, "krb5_storage_from_fd");
while(1) {
struct sockaddr_storage sa;
krb5_socklen_t salen = sizeof(sa);
struct timeval tv;
krb5_address a;
krb5_data d, r;
uint32_t t, clty, tag;
char astr[80];
ret = krb5_ret_uint32(sp, &t);
if (ret == HEIM_ERR_EOF)
break;
else if (ret)
krb5_errx(context, 1, "krb5_ret_uint32(version)");
if (t != 1)
krb5_errx(context, 1, "version not 1");
ret = krb5_ret_uint32(sp, &t);
if (ret)
krb5_errx(context, 1, "krb5_ret_uint32(time)");
ret = krb5_ret_address(sp, &a);
if (ret)
krb5_errx(context, 1, "krb5_ret_address");
ret = krb5_ret_data(sp, &d);
if (ret)
krb5_errx(context, 1, "krb5_ret_data");
ret = krb5_ret_uint32(sp, &clty);
if (ret)
krb5_errx(context, 1, "krb5_ret_uint32(class|type)");
ret = krb5_ret_uint32(sp, &tag);
if (ret)
krb5_errx(context, 1, "krb5_ret_uint32(tag)");
ret = krb5_addr2sockaddr (context, &a, (struct sockaddr *)&sa,
//.........这里部分代码省略.........
示例3: main
int
main(int argc, char *argv[])
{
char *System = NULL;
int c, i;
char *p;
const char *q;
char sbuf[12];
int cmdlineBR;
int fcarg;
setprogname(argv[0]);
gid = getgid();
egid = getegid();
uid = getuid();
euid = geteuid();
if (strcmp(getprogname(), "cu") == 0) {
cumode = 1;
cumain(argc, argv);
goto cucommon;
}
if (argc > 4)
tipusage();
if (!isatty(0))
errx(EXIT_FAILURE, "must be interactive");
cmdlineBR = 0;
while((c = getopt(argc, argv, "v0123456789")) != -1) {
switch(c) {
case 'v':
vflag++;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
cmdlineBR = cmdlineBR * 10 + (c - '0');
BR = cmdlineBR;
break;
default:
warnx("%s, unknown option", argv[1]);
break;
}
}
argc -= optind;
argv += optind;
if (argc != 1)
tipusage();
else
System = argv[0];
if (System == NULL)
goto notnumber;
if (isalpha((unsigned char)*System))
goto notnumber;
/*
* System name is really a phone number...
* Copy the number then stomp on the original (in case the number
* is private, we don't want 'ps' or 'w' to find it).
*/
if (strlen(System) > sizeof PNbuf - 1) {
errx(1, "phone number too long (max = %d bytes)",
(int)sizeof(PNbuf) - 1);
}
(void)strlcpy(PNbuf, System, sizeof(PNbuf));
for (p = System; *p; p++)
*p = '\0';
PN = PNbuf;
(void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR);
System = sbuf;
notnumber:
(void)signal(SIGINT, cleanup);
(void)signal(SIGQUIT, cleanup);
(void)signal(SIGHUP, cleanup);
(void)signal(SIGTERM, cleanup);
if ((i = hunt(System)) == 0) {
errx(3, "all ports busy");
}
if (i == -1) {
errx(3, "link down");
}
setbuf(stdout, NULL);
/*
* Kludge, their's no easy way to get the initialization
* in the right order, so force it here
*/
if ((PH = getenv("PHONES")) == NULL)
PH = path_phones;
vinit(); /* init variables */
setparity("none"); /* set the parity table */
//.........这里部分代码省略.........
示例4: main
int
main(int argc, char *argv[])
{
struct ulfs_args args;
char canon_dev[UKFS_DEVICE_MAXPATHLEN], canon_dir[MAXPATHLEN];
char rawdev[MAXPATHLEN];
struct p2k_mount *p2m;
pthread_t cleanerthread;
struct ukfs_part *part;
int mntflags;
int rv;
setprogname(argv[0]);
puffs_unmountonsignal(SIGINT, true);
puffs_unmountonsignal(SIGTERM, true);
if (argc >= 3) {
UKFS_DEVICE_ARGVPROBE(&part);
if (part != ukfs_part_none) {
errx(1, "lfs does not currently support "
"embedded partitions");
}
}
mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir);
/* Reset getopt for lfs_cleaner_main. */
optreset = 1;
optind = 1;
p2m = p2k_init(0);
if (!p2m)
err(1, "init p2k");
/*
* XXX: this particular piece inspired by the cleaner code.
* obviously FIXXXME along with the cleaner.
*/
sprintf(rawdev, "/dev/r%s", canon_dev+5);
rump_pub_etfs_register(rawdev, canon_dev, RUMP_ETFS_CHR);
/*
* We basically have two choices:
* 1) run the cleaner in another process and do rump ipc syscalls
* 2) run it off a thread in this process and do rump syscalls
* as function calls.
*
* opt for "2" for now
*/
#ifdef CLEANER_TESTING
ukfs_mount(MOUNT_LFS, canon_dev, canon_dir, mntflags,
&args, sizeof(args));
cleaner(canon_dir);
#endif
if (p2k_setup_diskfs(p2m, MOUNT_LFS, canon_dev, part, canon_dir,
mntflags, &args, sizeof(args)) == -1)
err(1, "mount");
ukfs_part_release(part);
#ifndef CLEANER_TESTING
if ((mntflags & MNT_RDONLY) == 0) {
if (pthread_create(&cleanerthread, NULL,
cleaner, canon_dir) == -1)
err(1, "cannot start cleaner");
}
#endif
rv = p2k_mainloop(p2m);
if (rv == -1)
err(1, "fs service");
return 0;
}
示例5: main
int
main(int argc, char **argv)
{
krb5_context context;
krb5_error_code ret;
krb5_creds cred;
krb5_preauthtype pre_auth_types[] = {KRB5_PADATA_ENC_TIMESTAMP};
krb5_get_init_creds_opt *get_options;
krb5_verify_init_creds_opt verify_options;
krb5_principal principal = NULL;
int optidx = 0;
setprogname (argv[0]);
if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
usage(1);
if (help_flag)
usage (0);
if(version_flag) {
print_version(NULL);
exit(0);
}
argc -= optidx;
argv += optidx;
ret = krb5_init_context(&context);
if (ret)
errx (1, "krb5_init_context failed: %d", ret);
ret = krb5_get_init_creds_opt_alloc (context, &get_options);
if (ret)
krb5_err(context, 1, ret, "krb5_get_init_creds_opt_alloc");
krb5_get_init_creds_opt_set_preauth_list (get_options,
pre_auth_types,
1);
krb5_verify_init_creds_opt_init (&verify_options);
if (argc) {
ret = krb5_parse_name(context, argv[0], &principal);
if (ret)
krb5_err(context, 1, ret, "krb5_parse_name: %s", argv[0]);
} else {
ret = krb5_get_default_principal(context, &principal);
if (ret)
krb5_err(context, 1, ret, "krb5_get_default_principal");
}
ret = krb5_get_init_creds_password (context,
&cred,
principal,
NULL,
krb5_prompter_posix,
NULL,
0,
NULL,
get_options);
if (ret)
krb5_err(context, 1, ret, "krb5_get_init_creds");
ret = krb5_verify_init_creds (context,
&cred,
NULL,
NULL,
NULL,
&verify_options);
if (ret)
krb5_err(context, 1, ret, "krb5_verify_init_creds");
krb5_free_cred_contents (context, &cred);
krb5_free_context (context);
return 0;
}
示例6: main
int
main(int argc, char **argv)
{
int ch, status;
unsigned int i;
int cflag, Cflag, Dflag, Uflag, wflag;
char *dir, *p;
FILE *spec1, *spec2;
setprogname(argv[0]);
cflag = Cflag = Dflag = Uflag = wflag = 0;
dir = NULL;
init_excludes();
spec1 = stdin;
spec2 = NULL;
while ((ch = getopt(argc, argv,
"bcCdDeE:f:F:I:ijk:K:lLmMnN:O:p:PqrR:s:StuUwWxX:"))
!= -1) {
switch((char)ch) {
case 'b':
bflag = 1;
break;
case 'c':
cflag = 1;
break;
case 'C':
Cflag = 1;
break;
case 'd':
dflag = 1;
break;
case 'D':
Dflag = 1;
break;
case 'E':
parsetags(&excludetags, optarg);
break;
case 'e':
eflag = 1;
break;
case 'f':
if (spec1 == stdin) {
spec1 = fopen(optarg, "r");
if (spec1 == NULL)
mtree_err("%s: %s", optarg,
strerror(errno));
} else if (spec2 == NULL) {
spec2 = fopen(optarg, "r");
if (spec2 == NULL)
mtree_err("%s: %s", optarg,
strerror(errno));
} else
usage();
break;
case 'F':
for (i = 0; i < __arraycount(flavors); i++)
if (strcmp(optarg, flavors[i].name) == 0) {
flavor = flavors[i].flavor;
break;
}
if (i == __arraycount(flavors))
usage();
break;
case 'i':
iflag = 1;
break;
case 'I':
parsetags(&includetags, optarg);
break;
case 'j':
jflag = 1;
break;
case 'k':
keys = F_TYPE;
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
case 'K':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
case 'l':
lflag = 1;
break;
case 'L':
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
break;
case 'm':
mflag = 1;
break;
case 'M':
mtree_Mflag = 1;
break;
case 'n':
nflag = 1;
//.........这里部分代码省略.........
示例7: main
int
main(int argc, char **argv)
{
krb5_error_code ret;
krb5_context context;
krb5_auth_context auth_context;
void *kadm_handle;
kadm5_server_context *server_context;
kadm5_config_params conf;
int master_fd;
krb5_ccache ccache;
krb5_principal server;
char **files;
int optidx = 0;
time_t reconnect_min;
time_t backoff;
time_t reconnect_max;
time_t reconnect;
time_t before = 0;
const char *master;
setprogname(argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
ret = krb5_init_context(&context);
if (ret)
errx (1, "krb5_init_context failed: %d", ret);
setup_signal();
if (config_file == NULL) {
if (asprintf(&config_file, "%s/kdc.conf", hdb_db_dir(context)) == -1
|| config_file == NULL)
errx(1, "out of memory");
}
ret = krb5_prepend_config_files_default(config_file, &files);
if (ret)
krb5_err(context, 1, ret, "getting configuration files");
ret = krb5_set_config_files(context, files);
krb5_free_config_files(files);
if (ret)
krb5_err(context, 1, ret, "reading configuration files");
argc -= optidx;
argv += optidx;
if (argc != 1)
usage(1);
master = argv[0];
#ifdef SUPPORT_DETACH
if (detach_from_console)
daemon(0, 0);
#endif
pidfile (NULL);
krb5_openlog (context, "ipropd-slave", &log_facility);
krb5_set_warn_dest(context, log_facility);
ret = krb5_kt_register(context, &hdb_kt_ops);
if(ret)
krb5_err(context, 1, ret, "krb5_kt_register");
time_before_lost = parse_time (server_time_lost, "s");
if (time_before_lost < 0)
krb5_errx (context, 1, "couldn't parse time: %s", server_time_lost);
memset(&conf, 0, sizeof(conf));
if(realm) {
conf.mask |= KADM5_CONFIG_REALM;
conf.realm = realm;
}
ret = kadm5_init_with_password_ctx (context,
KADM5_ADMIN_SERVICE,
NULL,
KADM5_ADMIN_SERVICE,
&conf, 0, 0,
&kadm_handle);
if (ret)
krb5_err (context, 1, ret, "kadm5_init_with_password_ctx");
server_context = (kadm5_server_context *)kadm_handle;
ret = kadm5_log_init (server_context);
if (ret)
krb5_err (context, 1, ret, "kadm5_log_init");
get_creds(context, keytab_str, &ccache, master);
//.........这里部分代码省略.........
示例8: main
int
main(int argc, char **argv)
{
krb5_error_code ret;
krb5_context context;
krb5_auth_context ac = NULL;
krb5_principal c1, c2;
krb5_authenticator authent;
krb5_keytab keytab;
krb5_socket_t sock = rk_INVALID_SOCKET;
HDB *db = NULL;
int optidx = 0;
char *tmp_db;
krb5_log_facility *fac;
int nprincs;
setprogname(argv[0]);
ret = krb5_init_context(&context);
if(ret)
exit(1);
ret = krb5_openlog(context, "hpropd", &fac);
if(ret)
errx(1, "krb5_openlog");
krb5_set_warn_dest(context, fac);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(local_realm != NULL)
krb5_set_default_realm(context, local_realm);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
argc -= optidx;
argv += optidx;
if (argc != 0)
usage(1);
if (database == NULL)
database = hdb_default_db(context);
if(from_stdin) {
sock = STDIN_FILENO;
} else {
struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
socklen_t sin_len = sizeof(ss);
char addr_name[256];
krb5_ticket *ticket;
char *server;
sock = STDIN_FILENO;
#ifdef SUPPORT_INETD
if (inetd_flag == -1) {
if (getpeername (sock, sa, &sin_len) < 0) {
inetd_flag = 0;
} else {
inetd_flag = 1;
}
}
#else
inetd_flag = 0;
#endif
if (!inetd_flag) {
mini_inetd (krb5_getportbyname (context, "hprop", "tcp",
HPROP_PORT), &sock);
}
sin_len = sizeof(ss);
if(getpeername(sock, sa, &sin_len) < 0)
krb5_err(context, 1, errno, "getpeername");
if (inet_ntop(sa->sa_family,
socket_get_address (sa),
addr_name,
sizeof(addr_name)) == NULL)
strlcpy (addr_name, "unknown address",
sizeof(addr_name));
krb5_log(context, fac, 0, "Connection from %s", addr_name);
ret = krb5_kt_register(context, &hdb_kt_ops);
if(ret)
krb5_err(context, 1, ret, "krb5_kt_register");
if (ktname != NULL) {
ret = krb5_kt_resolve(context, ktname, &keytab);
if (ret)
krb5_err (context, 1, ret, "krb5_kt_resolve %s", ktname);
} else {
ret = krb5_kt_default (context, &keytab);
if (ret)
krb5_err (context, 1, ret, "krb5_kt_default");
//.........这里部分代码省略.........
示例9: main
int
main(int argc, char **argv)
{
int aflag, dflag, oflag, qflag;
const char *filename;
int dependfile;
char *buf, *lim, *ptr, *line, *suf, *colon, *eol;
int ok_ind, ch;
size_t sz;
int fd;
size_t slen;
const char *fname;
const char *suffixes = NULL, *s;
suff_list_t *suff_list = NULL, *sl;
#ifdef __minix
size_t nr;
#endif
suf = NULL; /* XXXGCC -Wuninitialized [sun2] */
sl = NULL; /* XXXGCC -Wuninitialized [sun2] */
setlocale(LC_ALL, "");
setprogname(argv[0]);
aflag = O_WRONLY | O_APPEND | O_CREAT | O_TRUNC;
dflag = 0;
oflag = 0;
qflag = 0;
filename = DEFAULT_FILENAME;
dependfile = -1;
opterr = 0; /* stop getopt() bleating about errors. */
for (;;) {
ok_ind = optind;
ch = getopt(argc, argv, "aDdf:opqs:");
switch (ch) {
case -1:
ok_ind = optind;
break;
case 'a': /* Append to output file */
aflag &= ~O_TRUNC;
continue;
case 'D': /* Process *.d files (don't run cc -M) */
dflag = 2; /* Read names from stdin */
opterr = 1;
continue;
case 'd': /* Process *.d files (don't run cc -M) */
dflag = 1;
opterr = 1;
continue;
case 'f': /* Name of output file */
filename = optarg;
continue;
case 'o': /* Mark dependant files .OPTIONAL */
oflag = 1;
continue;
case 'p': /* Program mode (x.o: -> x:) */
suffixes = "";
continue;
case 'q': /* Quiet */
qflag = 1;
continue;
case 's': /* Suffix list */
suffixes = optarg;
continue;
default:
if (dflag)
usage();
/* Unknown arguments are passed to "${CC} -M" */
break;
}
break;
}
argc -= ok_ind;
argv += ok_ind;
if ((argc == 0 && !dflag) || (argc != 0 && dflag == 2))
usage();
if (suffixes != NULL) {
/* parse list once and save names and lengths */
/* allocate an extra entry to mark end of list */
for (sz = 1, s = suffixes; *s != 0; s++)
if (*s == '.')
sz++;
suff_list = calloc(sz, sizeof *suff_list);
if (suff_list == NULL)
err(2, "malloc");
sl = suff_list;
for (s = suffixes; (s = strchr(s, '.')); s += sz, sl++) {
sz = strcspn(s, ", ");
if (sz > sizeof sl->suff)
errx(2, "suffix too long");
sl->len = sz;
memcpy(sl->suff, s, sz);
}
}
dependfile = open(filename, aflag, 0666);
if (dependfile == -1)
//.........这里部分代码省略.........
示例10: main
int
main(int argc, char **argv)
{
krb5_error_code ret;
krb5_context context;
krb5_ccache ccache = NULL;
HDB *db = NULL;
int optidx = 0;
int type, exit_code;
setprogname(argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag){
print_version(NULL);
exit(0);
}
ret = krb5_init_context(&context);
if(ret)
exit(1);
/* We may be reading an old database encrypted with a DES master key. */
ret = krb5_allow_weak_crypto(context, 1);
if(ret)
krb5_err(context, 1, ret, "krb5_allow_weak_crypto");
if(local_realm)
krb5_set_default_realm(context, local_realm);
if(encrypt_flag && decrypt_flag)
krb5_errx(context, 1,
"only one of `--encrypt' and `--decrypt' is meaningful");
if(source_type != NULL) {
type = parse_source_type(source_type);
if(type == 0)
krb5_errx(context, 1, "unknown source type `%s'", source_type);
} else
type = HPROP_HEIMDAL;
if(!to_stdout)
get_creds(context, &ccache);
if(decrypt_flag || encrypt_flag) {
ret = hdb_read_master_key(context, mkeyfile, &mkey5);
if(ret && ret != ENOENT)
krb5_err(context, 1, ret, "hdb_read_master_key");
if(ret)
krb5_errx(context, 1, "No master key file found");
}
switch(type) {
case HPROP_MIT_DUMP:
if (database == NULL)
krb5_errx(context, 1, "no dump file specified");
break;
case HPROP_HEIMDAL:
ret = hdb_create (context, &db, database);
if(ret)
krb5_err(context, 1, ret, "hdb_create: %s", database);
ret = db->hdb_open(context, db, O_RDONLY, 0);
if(ret)
krb5_err(context, 1, ret, "db->hdb_open");
break;
default:
krb5_errx(context, 1, "unknown dump type `%d'", type);
break;
}
if (to_stdout)
exit_code = dump_database (context, type, database, db);
else
exit_code = propagate_database (context, type, database,
db, ccache, optidx, argc, argv);
if(ccache != NULL)
krb5_cc_destroy(context, ccache);
if(db != NULL)
(*db->hdb_destroy)(context, db);
krb5_free_context(context);
return exit_code;
}
示例11: main
int
main(int argc, char *argv[])
{
struct passwd *pw;
struct group *gptr;
char *arg;
const char *cp;
char buf[MAXPATHLEN];
int i, f, errs, c;
struct stat stb;
int oerrno;
euid = geteuid();
uid = getuid();
seteuid(uid);
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, cleanup);
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, cleanup);
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
signal(SIGQUIT, cleanup);
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
signal(SIGTERM, cleanup);
setprogname(*argv);
gethostname(host, sizeof (host));
host[sizeof(host) - 1] = '\0';
openlog("lpd", 0, LOG_LPR);
errs = 0;
while ((c = getopt(argc, argv,
":#:1:2:3:4:C:J:P:RT:U:cdfghi:lmnopqrstvw:")) != -1) {
switch (c) {
case '#': /* n copies */
if (isdigit((unsigned char)*optarg)) {
i = atoi(optarg);
if (i > 0)
ncopies = i;
}
break;
case '4': /* troff fonts */
case '3':
case '2':
case '1':
fonts[optopt - '1'] = optarg;
break;
case 'C': /* classification spec */
hdr++;
class = optarg;
break;
case 'J': /* job name */
hdr++;
jobname = optarg;
break;
case 'P': /* specifiy printer name */
printer = optarg;
break;
case 'R': /* print request id */
Rflag++;
break;
case 'T': /* pr's title line */
title = optarg;
break;
case 'U': /* user name */
hdr++;
person = optarg;
break;
case 'c': /* print cifplot output */
case 'd': /* print tex output (dvi files) */
case 'g': /* print graph(1G) output */
case 'l': /* literal output */
case 'o': /* print postscript output */
case 'n': /* print ditroff output */
case 'p': /* print using ``pr'' */
case 't': /* print troff output (cat files) */
case 'v': /* print vplot output */
format = optopt;
break;
case 'f': /* print fortran output */
format = 'r';
break;
case 'h': /* toggle want of header page */
hdr = !hdr;
break;
case 'i': /* indent output */
iflag++;
indent = atoi(optarg);
//.........这里部分代码省略.........
示例12: main
int
main(int argc, char **argv)
{
int port = 0;
int optidx = 0;
int ret = 1;
char *host = NULL;
setprogname (argv[0]);
if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
&optidx))
usage (1);
if (help_flag)
usage (0);
if (version_flag) {
print_version (NULL);
return 0;
}
if (optidx != argc - 1)
usage (1);
host = argv[optidx];
if (port_str) {
struct servent *s = roken_getservbyname (port_str, "tcp");
if (s)
port = s->s_port;
else {
char *ptr;
port = strtol (port_str, &ptr, 10);
if (port == 0 && ptr == port_str)
errx (1, "Bad port `%s'", port_str);
port = htons(port);
}
}
if (user == NULL) {
user = get_default_username ();
if (user == NULL)
errx (1, "who are you?");
}
if (!passive_flag)
passive_flag = check_for_passive (getenv("DISPLAY"));
#if defined(HAVE_KERNEL_ENABLE_DEBUG)
if (krb_debug_flag)
krb_enable_debug ();
#endif
#ifdef KRB5
if (ret && use_v5) {
if (port == 0)
port = krb5_getportbyname(NULL, "kx", "tcp", KX_PORT);
ret = doit_v5 (host, port, user,
passive_flag, debug_flag, keepalive_flag, tcp_flag);
}
#endif
return ret;
}
示例13: main
int
main(int argc, char **argv)
{
OM_uint32 major, minor;
gss_cred_id_t from_cred = GSS_C_NO_CREDENTIAL;
gss_cred_id_t to_cred = GSS_C_NO_CREDENTIAL;
gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
char *from_env;
char *to_env;
int optidx = 0;
setprogname(argv[0]);
if (getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
usage(1);
if (help_flag)
usage (0);
if (version_flag){
print_version(NULL);
exit(0);
}
argc -= optidx;
argv += optidx;
if (argc < 2)
errx(1, "required arguments missing");
if (argc > 2)
errx(1, "too many arguments");
if (asprintf(&from_env, "KRB5CCNAME=%s", argv[0]) == -1 || from_env == NULL)
err(1, "out of memory");
if (asprintf(&to_env, "KRB5CCNAME=%s", argv[1]) == -1 || to_env == NULL)
err(1, "out of memory");
putenv(from_env);
major = gss_add_cred(&minor, GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME,
GSS_KRB5_MECHANISM, GSS_C_INITIATE, GSS_C_INDEFINITE,
GSS_C_INDEFINITE, &from_cred, NULL, NULL, NULL);
if (major != GSS_S_COMPLETE)
gss_err(1, major, minor, GSS_KRB5_MECHANISM,
"failed to acquire creds from %s", argv[0]);
putenv(to_env);
major = gss_store_cred(&minor, from_cred, GSS_C_INITIATE,
GSS_KRB5_MECHANISM, 1, 1, NULL, NULL);
if (major != GSS_S_COMPLETE)
gss_err(1, major, minor, GSS_KRB5_MECHANISM,
"failed to store creds into %s", argv[1]);
(void) gss_release_cred(&minor, &from_cred);
(void) gss_release_cred(&minor, &to_cred);
major = gss_add_cred(&minor, GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME,
GSS_KRB5_MECHANISM, GSS_C_INITIATE, GSS_C_INDEFINITE,
GSS_C_INDEFINITE, &cred, NULL, NULL, NULL);
if (major != GSS_S_COMPLETE)
gss_err(1, major, minor, GSS_KRB5_MECHANISM,
"failed to acquire creds from %s", argv[1]);
(void) gss_release_cred(&minor, &cred);
putenv("KRB5CCNAME");
free(from_env);
free(to_env);
return 0;
}
示例14: main
int
main(int argc, char **argv, char **envp)
{
FILE *config;
char *line, *cp, *from, *to, *ap;
const char *progname;
size_t len, lineno = 0;
int i;
struct arglist al;
/* change progname to mailwrapper so we get sensible error messages */
progname = getprogname();
setprogname("mailwrapper");
if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
openlog("mailwrapper", LOG_PID, LOG_MAIL);
syslog(LOG_INFO, "can't open %s, using %s as default MTA",
_PATH_MAILERCONF, _PATH_DEFAULTMTA);
closelog();
execve(_PATH_DEFAULTMTA, argv, envp);
err(1, "cannot exec %s", _PATH_DEFAULTMTA);
/*NOTREACHED*/
}
initarg(&al);
addarg(&al, argv[0], 0);
for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
if (feof(config))
errx(1, "no mapping in %s", _PATH_MAILERCONF);
err(1, NULL);
}
#define WS " \t\n"
cp = line;
cp += strspn(cp, WS);
if (cp[0] == '\0') {
/* empty line */
free(line);
continue;
}
if ((from = strsep(&cp, WS)) == NULL)
goto parse_error;
cp += strspn(cp, WS);
if ((to = strsep(&cp, WS)) == NULL)
goto parse_error;
if (strcmp(from, progname) == 0) {
for (ap = strsep(&cp, WS); ap != NULL;
ap = strsep(&cp, WS))
if (*ap)
addarg(&al, ap, 0);
break;
}
free(line);
}
fclose(config);
for (i = 1; i < argc; i++)
addarg(&al, argv[i], 0);
addarg(&al, NULL, 0);
execve(to, al.argv, envp);
err(1, "cannot exec %s", to);
/*NOTREACHED*/
parse_error:
errx(1, "parse error in %s at line %lu",
_PATH_MAILERCONF, (u_long)lineno);
/*NOTREACHED*/
}
示例15: main
int
main(int argc, char **argv)
{
int ret;
const char *file;
const char *name = NULL;
int optidx = 0;
char **arg = NULL;
size_t len = 0, i;
setprogname(argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
if (argc == optidx) {
file = "stdin";
name = "stdin";
yyin = stdin;
} else {
file = argv[optidx];
yyin = fopen (file, "r");
if (yyin == NULL)
err (1, "open %s", file);
if (argc == optidx + 1) {
char *p;
name = estrdup(file);
p = strrchr(name, '.');
if (p)
*p = '\0';
} else
name = argv[optidx + 1];
}
/*
* Parse extra options file
*/
if (option_file) {
char buf[1024];
FILE *opt;
opt = fopen(option_file, "r");
if (opt == NULL) {
perror("open");
exit(1);
}
arg = calloc(2, sizeof(arg[0]));
if (arg == NULL) {
perror("calloc");
exit(1);
}
arg[0] = option_file;
arg[1] = NULL;
len = 1;
while (fgets(buf, sizeof(buf), opt) != NULL) {
buf[strcspn(buf, "\n\r")] = '\0';
arg = realloc(arg, (len + 2) * sizeof(arg[0]));
if (arg == NULL) {
perror("malloc");
exit(1);
}
arg[len] = strdup(buf);
if (arg[len] == NULL) {
perror("strdup");
exit(1);
}
arg[len + 1] = NULL;
len++;
}
fclose(opt);
optidx = 0;
if(getarg(args, num_args, len, arg, &optidx))
usage(1);
if (len != optidx) {
fprintf(stderr, "extra args");
exit(1);
}
}
init_generate (file, name);
if (one_code_file)
generate_header_of_codefile(name);
initsym ();
ret = yyparse ();
if(ret != 0 || error_flag != 0)
exit(1);
close_generate ();
if (argc != optidx)
//.........这里部分代码省略.........