static void change_attributes (const char * name) { unsigned long flags; STRUCT_STAT st; if (LSTAT (name, &st) == -1) { com_err (program_name, errno, _("while trying to stat %s"), name); return; } if (S_ISLNK(st.st_mode) && recursive) return; /* Don't try to open device files, fifos etc. We probably ought to display an error if the file was explicitly given on the command line (whether or not recursive was requested). */ if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode)) return; if (set) { if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, sf, 0); printf ("\n"); } if (fsetflags (name, sf) == -1) perror (name); } else { if (fgetflags (name, &flags) == -1) com_err (program_name, errno, _("while reading flags on %s"), name); else { if (rem) flags &= ~rf; if (add) flags |= af; if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, flags, 0); printf ("\n"); } if (!S_ISDIR(st.st_mode)) flags &= ~EXT2_DIRSYNC_FL; if (fsetflags (name, flags) == -1) com_err (program_name, errno, _("while setting flags on %s"), name); } } if (set_version) { if (verbose) printf (_("Version of %s set as %lu\n"), name, version); if (fsetversion (name, version) == -1) com_err (program_name, errno, _("while setting version on %s"), name); } if (S_ISDIR(st.st_mode) && recursive) iterate_on_dir (name, chattr_dir_proc, NULL); }
static void change_attributes(const char *name, struct globals *gp) { unsigned long fsflags; struct stat st; if (lstat(name, &st) != 0) { bb_perror_msg("stat %s", name); return; } if (S_ISLNK(st.st_mode) && gp->recursive) return; /* Don't try to open device files, fifos etc. We probably * ought to display an error if the file was explicitly given * on the command line (whether or not recursive was * requested). */ if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode)) return; if (gp->flags & OPT_SET_VER) if (fsetversion(name, gp->version) != 0) bb_perror_msg("setting version on %s", name); if (gp->flags & OPT_SET) { fsflags = gp->af; } else { if (fgetflags(name, &fsflags) != 0) { bb_perror_msg("reading flags on %s", name); goto skip_setflags; } /*if (gp->flags & OPT_REM) - not needed, rf is zero otherwise */ fsflags &= ~gp->rf; /*if (gp->flags & OPT_ADD) - not needed, af is zero otherwise */ fsflags |= gp->af; /* What is this? And why it's not done for SET case? */ if (!S_ISDIR(st.st_mode)) fsflags &= ~EXT2_DIRSYNC_FL; } if (fsetflags(name, fsflags) != 0) bb_perror_msg("setting flags on %s", name); skip_setflags: if (gp->recursive && S_ISDIR(st.st_mode)) iterate_on_dir(name, chattr_dir_proc, gp); }
static void change_attributes(const char * name) { unsigned long fsflags; struct stat st; if (lstat(name, &st) == -1) { bb_error_msg("stat %s failed", name); return; } if (S_ISLNK(st.st_mode) && recursive) return; /* Don't try to open device files, fifos etc. We probably * ought to display an error if the file was explicitly given * on the command line (whether or not recursive was * requested). */ if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode)) return; if (flags & OPT_SET_VER) if (fsetversion(name, version) == -1) bb_error_msg("setting version on %s", name); if (flags & OPT_SET) { fsflags = sf; } else { if (fgetflags(name, &fsflags) == -1) { bb_error_msg("reading flags on %s", name); goto skip_setflags; } if (flags & OPT_REM) fsflags &= ~rf; if (flags & OPT_ADD) fsflags |= af; if (!S_ISDIR(st.st_mode)) fsflags &= ~EXT2_DIRSYNC_FL; } if (fsetflags(name, fsflags) == -1) bb_error_msg("setting flags on %s", name); skip_setflags: if (S_ISDIR(st.st_mode) && recursive) iterate_on_dir(name, chattr_dir_proc, NULL); }
static int change_attributes(const char * name) { unsigned long flags; STRUCT_STAT st; if (LSTAT (name, &st) == -1) { if (!silent) com_err (program_name, errno, _("while trying to stat %s"), name); return -1; } if (set) { if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, sf, 0); printf ("\n"); } if (fsetflags (name, sf) == -1) perror (name); } else { if (fgetflags (name, &flags) == -1) { if (!silent) com_err (program_name, errno, _("while reading flags on %s"), name); return -1; } else { if (rem) flags &= ~rf; if (add) flags |= af; if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, flags, 0); printf ("\n"); } if (!S_ISDIR(st.st_mode)) flags &= ~EXT2_DIRSYNC_FL; if (fsetflags (name, flags) == -1) { if (!silent) com_err(program_name, errno, _("while setting flags on %s"), name); return -1; } } } if (set_version) { if (verbose) printf (_("Version of %s set as %lu\n"), name, version); if (fsetversion (name, version) == -1) { if (!silent) com_err (program_name, errno, _("while setting version on %s"), name); return -1; } } if (S_ISDIR(st.st_mode) && recursive) return iterate_on_dir (name, chattr_dir_proc, NULL); return 0; }
static void tcp_srv_event(int fd, short events, void *userdata) { struct server_socket *sock = userdata; struct sockaddr_in6 addr; socklen_t addrlen = sizeof(struct sockaddr_in6); struct client *cli = NULL; char host[64]; char port[16]; int cli_fd, on = 1; struct timeval timeout = { CLI_RD_TIMEOUT, 0 }; /* receive TCP connection from kernel */ cli_fd = accept(sock->fd, (struct sockaddr *) &addr, &addrlen); if (cli_fd < 0) { syslogerr("tcp accept"); goto err_out; } srv.stats.tcp_accept++; cli = cli_alloc(cli_fd, &addr, addrlen, true); if (!cli) { applog(LOG_ERR, "OOM"); close(cli_fd); return; } /* mark non-blocking, for upcoming poll use */ if (fsetflags("tcp client", cli->fd, O_NONBLOCK) < 0) goto err_out_fd; /* disable delay of small output packets */ if (setsockopt(cli->fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) applog(LOG_WARNING, "TCP_NODELAY failed: %s", strerror(errno)); /* turn on TCP keep-alive */ on = 1; if (setsockopt(cli->fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0) applog(LOG_WARNING, "SO_KEEPALIVE failed: %s", strerror(errno)); event_set(&cli->ev, cli->fd, EV_READ | EV_PERSIST, tcp_cli_event, cli); /* pretty-print incoming cxn info */ getnameinfo((struct sockaddr *) &cli->addr, addrlen, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); host[sizeof(host) - 1] = 0; port[sizeof(port) - 1] = 0; applog(LOG_INFO, "client host %s port %s connected%s", host, port, false ? " via SSL" : ""); strcpy(cli->addr_host, host); strcpy(cli->addr_port, port); if (event_add(&cli->ev, &timeout) < 0) { applog(LOG_ERR, "unable to ready cli fd for polling"); goto err_out_fd; } cli->ev_mask = EV_READ; if (!tcp_read(&cli->rst, &cli->ubbp, sizeof(cli->ubbp), cli_read_hdr, NULL)) goto err_out_fd; return; err_out_fd: err_out: cli_free(cli); }