Status BinCommon::wr_value(CommandInitiator* thread, const String& val)
 {
   uint size = val.size();
   if (wr_value(thread, size) != OK) return ERR_ENCODE;
   if (size > 0)
     if (m_transport->bl_write_bytes(thread, size,val.data()) != TransportInterface::OK) return ERR_ENCODE;
   return OK;
 }
Example #2
0
/*
 * This procedure stores the current state of the lists (lwps, processes,
 * users and project) into the file defined by 'file'.
 * param file - the file name to be used
 * return 0, or -1 on error and store the error message in
 *		the global buffer 'errmsg'.
 */
int
list_store(char *file)
{
	int	storefd;
	time_t  tv;
	char 	*tstr;
	int 	ret = -1;

	if ((storefd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR))
			== -1) {
		format_err("can't open list db: %s\n", file);
		(void) fprintf(stderr, errmsg);
		return (-1);
	}
	log_msg("writing persistence file: %s\n", file);

	/*
	 * the next do {..} while (false); statement is a replacement
	 * of goto;
	 */
	do {
		if (open_prot(storefd, "w") == -1) {
			format_err("can't open list db: %s\n", file);
			(void) fprintf(stderr, errmsg);
			break;
		}
		(void) time(&tv);
		tstr = ctime(&tv);
		if (wr_string("# RDS data base file generated on: ") == -1)
			break;
		if (wr_string(tstr) == -1)
			break;
		if (wr_value(LTDB_VERSION_KEY, LTDB_VERSION) == -1)
			break;
		if (wr_value(LTDB_TIMESTAMP, tv) == -1)
			break;
		/* we will write 4 lists */
		if (wr_lshead(4) != 0) {
			format_err("can't write into list db: %s\n",
					"./listdb");
			break;
		}
		if (list_write(L_LWP, 0) == -1)
			break;
		if (list_write(L_PRC_SI, 0) == -1)
			break;
		if (list_write(L_USR_SI, 0) == -1)
			break;
		if (list_write(L_PRJ_SI, 0) == -1)
			break;
		ret = 0;
	} while (ret);

	if (ret == 0) {
		struct stat stat_buf;
		(void) fstat(storefd, &stat_buf);
		log_msg("wrote: %ld bytes\n", stat_buf.st_size);
	}

	/* close_prot(); */
	(void) close(storefd);

	return (ret);
}
 Status BinCommon::wr_value(CommandInitiator* thread, const Filename& val)
 {
   return wr_value(thread, (const String&) val) ;
 }