Exemplo n.º 1
0
Arquivo: Socket.cpp Projeto: crnt/x0
void Socket::setMode(Mode m)
{
	TRACE("setMode() %s -> %s", mode_str(mode_), mode_str(m));
	if (isClosed())
		return;

	if (m != mode_) {
		if (m != None) {
			TRACE("setMode: set flags");
			watcher_.set(fd_, static_cast<int>(m));

			if (!watcher_.is_active()) {
				TRACE("setMode: start watcher");
				watcher_.start();
			}
		} else {
			TRACE("stop watcher and timer");
			if (watcher_.is_active())
				watcher_.stop();

			if (timer_.is_active())
				timer_.stop();
		}

		mode_ = m;
	}
}
Exemplo n.º 2
0
int cmp_type(alpm_pkg_t *pkg, const char *path,
		struct archive_entry *entry, struct stat *st)
{
	const char *type = mode_str(archive_entry_filetype(entry));
	const char *ftype = mode_str(st->st_mode);

	if(type != ftype) {
		eprintf("%s: '%s' type mismatch (expected %s)\n",
				alpm_pkg_get_name(pkg), path, type);
		return 1;
	}

	return 0;
}
Exemplo n.º 3
0
void show_file_info(char *filename, struct stat *info_p) /* 打印文件的相关信息 */
{
	char modestr[11];

	mode_str(info_p->st_mode, modestr);

	if((strcmp(arr1,"-a") == 0) ||(strcmp(arr2,"-a") == 0))
	{
		printf("%s", modestr);
		printf("%3d ", (int)info_p->st_nlink);
		printf("%-8s", uid_str(info_p->st_uid));
		printf("%-8s", gid_str(info_p->st_gid));
		printf("%4ld ", (long)info_p->st_size);
		printf("%.12s ", 4 + ctime(&info_p->st_mtime));
		printf("%s\n", filename);
	}else if(filename[0] != '.')	//文件名第一个字符不为.就显示
	{
		printf("%s", modestr);
		printf("%3d ", (int)info_p->st_nlink);
		printf("%-8s", uid_str(info_p->st_uid));
		printf("%-8s", gid_str(info_p->st_gid));
		printf("%4ld ", (long)info_p->st_size);
		printf("%.12s ", 4 + ctime(&info_p->st_mtime));
		printf("%s\n", filename);
	}
}
Exemplo n.º 4
0
void Iss2::InstructionRequest::print( std::ostream &o ) const
{
    o << "<InsReq "
      << " mode " << mode_str(mode)
      << (valid ? "   valid" : " invalid")
      << " @ " << std::hex << std::showbase << addr
      << ">";
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: jjzhang/dlm
static const char *pr_grmode(struct lkb *lkb)
{
	if (lkb->status == DLM_LKSTS_GRANTED || lkb->status == DLM_LKSTS_CONVERT)
		return mode_str(lkb->grmode);
	else if (lkb->status == DLM_LKSTS_WAITING || lkb->rsb_lookup)
		return "--";
	else
		return "XX";
}
Exemplo n.º 6
0
Arquivo: Socket.cpp Projeto: crnt/x0
void Socket::inspect(Buffer& out)
{
	// only complain about potential bugs...

	out << "fd:" << fd_ << ", " << "timer:" << timer_.is_active() << "<br/>";

	out << "io.ev:" << mode_str((Mode)watcher_.events) << ", "
		<< "io.x0:" << mode_str(mode_) << "<br/>";

	if (mode_ != watcher_.events) {
		out << "<b>backend events differ from watcher mask</b><br/>";
	}

	struct stat st;
	if (fstat(fd_, &st) < 0) {
		out << "fd stat error: " << strerror(errno) << "<br/>";
	}
}
Exemplo n.º 7
0
void show_file_info(char *filename, struct stat *info_p) 
{
       char modestr[11];

        mode_str(info_p->st_mode, modestr);
        printf("%s", modestr);
        printf("%3d ", (int)info_p->st_nlink);
        printf("%-8s", uid_str(info_p->st_uid));
        printf("%-8s", gid_str(info_p->st_gid));
        printf("%4ld ", (long)info_p->st_size);
        printf("%.12s ", 4 + ctime(&info_p->st_mtime));
        printf("%s\n", filename);
}
Exemplo n.º 8
0
void Iss2::DataRequest::print( std::ostream &o ) const
{
    o << "<DataReq"
      << " mode " << mode_str(mode)
      << (valid ? "   valid" : " invalid")
      << " type " << type_str(type);
    if ( type == XTN_READ || type == XTN_WRITE )
        //o << " (" << xtn_str((enum ExternalAccessType)addr) << ")";
        o << " (" << xtn_str((enum ExternalAccessType)(addr/4)) << ")";
    else
        o << " @ " << std::hex << std::showbase << addr;
    o << " wdata " << std::hex << std::showbase << wdata
      << " be " << std::hex << (int)be
      << ">";
}
Exemplo n.º 9
0
Arquivo: Socket.cpp Projeto: crnt/x0
void Socket::io(ev::io& /*io*/, int revents)
{
	lastActivityAt_.update(ev_now(loop_));

	TRACE("io(revents=0x%04X): mode=%s", revents, mode_str(mode_));

	timer_.stop();

	if (state_ == Connecting)
		onConnectComplete();
	else if (state_ == Handshake)
		handshake(revents);
	else if (callback_)
		callback_(this, callbackData_, revents);
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: jjzhang/dlm
static const char *pr_rqmode(struct lkb *lkb)
{
	static char buf[5];

	memset(buf, 0, sizeof(buf));

	if (lkb->status == DLM_LKSTS_GRANTED) {
		return "    ";
	} else if (lkb->status == DLM_LKSTS_CONVERT ||
		   lkb->status == DLM_LKSTS_WAITING ||
		   lkb->rsb_lookup) {
		sprintf(buf, "(%s)", mode_str(lkb->rqmode));
		return buf;
	} else {
		return "(XX)";
	}
}
Exemplo n.º 11
0
int
list_dir_internal(stralloc* dir, char type) {
  size_t l;
  struct dir_s d;
  stralloc pre;
  int dtype;
  int is_dir, is_symlink;
  size_t len;
#if !WINDOWS_NATIVE
  struct stat st;
  static dev_t root_dev;
#endif
  char *name, *s;
  (void)type;
  while(dir->len > 1 && IS_DIRSEP(dir->s[dir->len - 1])) dir->len--;
  stralloc_nul(dir);
#if !WINDOWS_NATIVE
  if(root_dev == 0) {
    if(stat(dir->s, &st) != -1) {
      root_dev = st.st_dev;
    }
  }
#endif
  if(dir_open(&d, dir->s) != 0) {
    buffer_puts(buffer_2, "ERROR: Opening directory ");
    buffer_putsa(buffer_2, dir);
    buffer_puts(buffer_2, " failed!\n");
    buffer_flush(buffer_2);
    goto end;
  }
  if(dir->s[dir->len - 1] != DIRSEP_C)
    stralloc_cats(dir, DIRSEP_S);
  l = dir->len;
  while((name = dir_read(&d))) {
    unsigned int mode = 0, nlink = 0, uid = 0, gid = 0;
    uint64 size = 0, mtime = 0;
    dtype = dir_type(&d);
    dir->len = l;
    if(str_equal(name, "") || str_equal(name, ".") || str_equal(name, "..")) {
      continue;
    }
    stralloc_readyplus(dir, str_len(name) + 1);
    str_copy(dir->s + dir->len, name);
    dir->len += str_len(name);
    is_symlink = !!(dtype & D_SYMLINK);
#if !WINDOWS_NATIVE
    if(!opt_deref && lstat(dir->s, &st) != -1) {
      if(root_dev && st.st_dev) {
        if(st.st_dev != root_dev) {
          continue;
        }
      }
    }
#endif
#if !WINDOWS_NATIVE
    if(S_ISLNK(st.st_mode)) {
      stat(dir->s, &st);
    }
    mode = st.st_mode;
#endif
    if(dtype) {
      is_dir = !!(dtype & D_DIRECTORY);
    } else {
#if WINDOWS_NATIVE
      is_dir = 0;
#else
      is_dir = !!S_ISDIR(mode);
#endif
    }
    if(dtype & D_SYMLINK)
      is_symlink = 1;
#if !WINDOWS_NATIVE
    nlink = st.st_nlink;
    uid = st.st_uid;
    gid = st.st_gid;
    size = st.st_size;
    mtime = st.st_mtime;
#else
    mode = (is_dir ? 0040000 : 0100000) | (is_symlink ? 0120000 : 0);
#if USE_READDIR
    if(!is_dir) {
      size = dir_size(&d); /* dir_INTERNAL(&d)->dir_entry->d_name); */
      mtime = dir_time(&d);
    } else {
      mtime = 0;
      size = 0;
    }
#else
    size = dir_size(&d);
    mtime = dir_time(&d, D_TIME_MODIFICATION);
#endif
#endif
    if(opt_list && size >= opt_minsize) {
      stralloc_init(&pre);
      /* Mode string */
      mode_str(&pre, mode);
      stralloc_catb(&pre, " ", 1);
      /* num links */
      make_num(&pre, nlink, 3);
      stralloc_catb(&pre, " ", 1);
      /* uid */
      make_num(&pre, uid, 0);
      stralloc_catb(&pre, " ", 1);
      /* gid */
      make_num(&pre, gid, 0);
      stralloc_catb(&pre, " ", 1);
      /* size */
      make_num(&pre, size, 6);
      stralloc_catb(&pre, " ", 1);
      /* time */
      make_num(&pre, mtime, 0);
      /*     make_time(&pre, mtime, 10); */
      stralloc_catb(&pre, " ", 1);
    }
    /* fprintf(stderr, "%d %08x\n", is_dir, dir_ATTRS(&d)); */
    if(is_dir)
      stralloc_catc(dir, opt_separator);
    if(dir->len > MAX_PATH) {
      buffer_puts(buffer_2, "ERROR: Directory ");
      buffer_putsa(buffer_2, dir);
      buffer_puts(buffer_2, " longer than MAX_PATH (" STRINGIFY(MAX_PATH) ")!\n");
      /*buffer_putulong(buffer_2, MAX_PATH);
      buffer_puts(buffer_2, ")!\n");*/
      buffer_flush(buffer_2);
      goto end;
    }
    s = dir->s;
    len = dir->len;
    if(len >= 2 && s[0] == '.' && IS_DIRSEP(s[1])) {
      len -= 2;
      s += 2;
    }
    if(opt_list && size >= opt_minsize)
      buffer_putsa(buffer_1, &pre);

    if(opt_relative_to) {
      size_t sz = str_len(opt_relative_to);
      if(str_diffn(s, opt_relative_to, sz) == 0) {
        s += sz;
        len -= sz;
        while(*s == '\\' || *s == '/') {
          s++;
          len--;
        }
      }
    }

    if(size >= opt_minsize) {
      buffer_put(buffer_1, s, len);
      buffer_put(buffer_1, "\n", 1);
      buffer_flush(buffer_1);
    }

    if(is_dir && (opt_deref || !is_symlink)) {
      dir->len--;
      list_dir_internal(dir, 0);
    }
  }
end:
  dir_close(&d);
  return 0;
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: jjzhang/dlm
static void do_lockdump(char *name)
{
	FILE *file;
	char path[PATH_MAX];
	char line[LOCK_LINE_MAX];
	char r_name[DLM_RESNAME_MAXLEN+1];
	int r_nodeid;
	int r_len;
	int rv;
	unsigned int tm;
	unsigned long long xid;
	uint32_t	id;
	int		nodeid;
	uint32_t	remid;
	int		ownpid;
	uint32_t	exflags;
	uint32_t	flags;
	int8_t		status;
	int8_t		grmode;
	int8_t		rqmode;

	snprintf(path, PATH_MAX, "/sys/kernel/debug/dlm/%s_locks", name);

	file = fopen(path, "r");
	if (!file) {
		fprintf(stderr, "can't open %s: %s\n", path, strerror(errno));
		return;
	}

	/* skip the header on the first line */
	if (!fgets(line, LOCK_LINE_MAX, file))
		return;

	while (fgets(line, LOCK_LINE_MAX, file)) {
		rv = sscanf(line, "%x %d %x %u %llu %x %x %hhd %hhd %hhd %u %d %d",
		       &id,
		       &nodeid,
		       &remid,
		       &ownpid,
		       &xid,
		       &exflags,
		       &flags,
		       &status,
		       &grmode,
		       &rqmode,
		       &tm,
		       &r_nodeid,
		       &r_len);

		if (rv != 13) {
			fprintf(stderr, "invalid debugfs line %d: %s\n",
				rv, line);
			return;
		}

		memset(r_name, 0, sizeof(r_name));
		parse_r_name(line, r_name);

		/* don't print MSTCPY locks without -M */
		if (!r_nodeid && nodeid) {
			if (!dump_mstcpy)
				continue;
			printf("id %08x gr %s rq %s pid %u MSTCPY %d \"%s\"\n",
				id, mode_str(grmode), mode_str(rqmode),
				ownpid, nodeid, r_name);
			continue;
		}

		/* A hack because dlm-kernel doesn't set rqmode back to IV when
		   a NOQUEUE convert fails, which means in a lockdump it looks
		   like a granted lock is still converting since rqmode is not
		   IV.  (does it make sense to include status in the output,
		   e.g. G,C,W?) */

		if (status == DLM_LKSTS_GRANTED)
			rqmode = LKM_IVMODE;

		printf("id %08x gr %s rq %s pid %u master %d \"%s\"\n",
			id, mode_str(grmode), mode_str(rqmode),
			ownpid, nodeid, r_name);
	}

	fclose(file);
}
Exemplo n.º 13
0
/*!

*/
std::string
gzfilebuf::makeModeString( std::ios_base::openmode mode,
                           int level,
                           int strategy )
{
    std::string mode_str("");
    mode_str.reserve( 6 );

    // set I/O
    bool testi = static_cast< bool >( mode & std::ios_base::in );
    bool testo = static_cast< bool >( mode & std::ios_base::out );

    if ( ( testi && testo )
         || ( ! testi && ! testo ) )
    {
        // invalid mode
        return std::string( "" );
    }

    if ( testi )
    {
        // If input mode, it is not necessary to consider
        // about compression level and strategy.
        mode_str = "rb";
        return mode_str;
    }

    if ( testo )
    {
        mode_str = "wb";
    }

    // set compression level
    if ( level == DEFAULT_COMPRESSION )
    {
        // nothing to do
    }
    else if ( NO_COMPRESSION <= level
              && level <= BEST_COMPRESSION )
    {
        char lvstr[4];
        snprintf( lvstr, 4, "%d", level );
        mode_str += lvstr;
    }
    else
    {
        // invalid compression level
        return std::string( "" );
    }

    // set strategy
    switch ( strategy ) {
    case DEFAULT_STRATEGY:
        // nothing to do
        break;
    case FILTERED:
        mode_str += "f";
        break;
    case HUFFMAN_ONLY:
        mode_str += "h";
        break;
    case RLE:
        mode_str += "R";
        break;
    default:
        // why reach here?
        break;
    }

    return mode_str;
}