[Commits] r665 - in trunk/daemon: lib src

new-commit at lists.openvcp.org new-commit at lists.openvcp.org
Sun May 3 14:32:13 UTC 2009


Author: cryptronic
Date: 2009-05-03 14:32:13 +0000 (Sun, 03 May 2009)
New Revision: 665

Modified:
   trunk/daemon/lib/fs.c
   trunk/daemon/src/userbackup.c
Log:
Bugfix to support linux vserver version >= 2.3


Modified: trunk/daemon/lib/fs.c
===================================================================
--- trunk/daemon/lib/fs.c	2009-05-03 13:46:36 UTC (rev 664)
+++ trunk/daemon/lib/fs.c	2009-05-03 14:32:13 UTC (rev 665)
@@ -44,35 +44,35 @@
 
 
 
-	filefd = open(filename, O_RDONLY);	
+	filefd = open(filename, O_RDONLY);
 	tmpfd = mkstemp(filename_tmp);
 
 
 	if(filefd != -1 && tmpfd != -1)
    	{
-	
+
 		while((len = read(filefd, data, 5000)) > 0)
 		{
 
 		  	data[len] = 0;
-		 
+
 			loc = data;
-			
+
 			while((next_loc = strstr(loc, searched)) != NULL)
 			{
 				write(tmpfd, loc, next_loc-loc);
 				write(tmpfd, replacement, strlen(replacement));
-	
+
 				loc = next_loc+strlen(searched);
 			}
-			
+
 			if(loc == data)
 				write(tmpfd, data, len);
 			else
 				write(tmpfd, loc, len-(loc-data));
 
 
-			
+
 			if(len == 5000)
 			{
 				//FIXME
@@ -85,11 +85,11 @@
 
 	close(filefd);
 	close(tmpfd);
-	
 
+
 	mv(filename_tmp, filename);
-	
 
+
 	return 1;
 }
 
@@ -120,27 +120,27 @@
 	int fd_old, fd_new;
 	int len, total = 0;
 	struct stat statbuf;
-	
+
 	fd_old = open(oldpath, O_RDONLY);
 
 	if(fd_old != -1)
 	{
-	
+
 		stat(oldpath, &statbuf);
 
-		
+
 		fd_new = open(newpath, O_WRONLY | O_CREAT | O_TRUNC, statbuf.st_mode);
 
 		if(fd_new != -1)
 		{
-			
+
 			while((len = read(fd_old, buf, 1024)) > 0)
 			{
 				write(fd_new, buf, len);
 
 				total += len;
 			}
-			
+
 			close(fd_new);
 		}
 
@@ -149,15 +149,15 @@
 
 
 	return total;
-} 
+}
 
 int file_attach(char *filename, char *data)
 {
 	int filefd;
 	int written_chars = -1;
-	
+
 	filefd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0755 );
-	
+
 	if(filefd != -1)
 	{
 		written_chars = write(filefd, data, strlen(data));
@@ -171,8 +171,8 @@
 {
 	int filefd;
 	int written_chars = -1;
-   
-	
+
+
 	filefd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0755);
 
 	if(filefd != -1)
@@ -180,7 +180,7 @@
 		written_chars = write(filefd, data, strlen(data));
 		close(filefd);
 	}
-   
+
 	return written_chars;
 
 }
@@ -190,24 +190,24 @@
 	int filefd, written_chars = 0;
 	char *data;
 	va_list list;
-   
-	
+
+
 	filefd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0755);
 
 	if(filefd != -1)
 	{
 		va_start(list, filename);
-			
+
 		while((data = va_arg(list, char *)) != NULL)
 		{
 			written_chars += write(filefd, data, strlen(data));
 		}
-		
+
 		va_end(list);
-	
+
 		close(filefd);
 	}
-   
+
 	return written_chars;
 
 }
@@ -218,13 +218,13 @@
 	int filefd;
 
 	filefd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0755);
-	
+
 	if(filefd != -1)
 	{
 		close(filefd);
 		return -1;
 	}
-   
+
 	return 1;
 }
 
@@ -232,32 +232,32 @@
 {
 	int filefd;
 	int read_chars=0,  total_chars=0;
-   
+
 	char *file_buffer = NULL;
   	char readbuffer[5000];
-	
+
 	filefd = open(filename, O_RDONLY, 0755);
-   
+
 	if(filefd != -1)
 	{
-		
+
 		while((read_chars = read(filefd, readbuffer, 5000)) > 0)
-		{  
-		
+		{
+
 			readbuffer[read_chars] = 0;
-	
+
 			file_buffer = (char *)realloc(file_buffer, total_chars+read_chars+1);
 			strcpy(file_buffer+total_chars,  readbuffer);
-	
+
 			total_chars += read_chars;
-		
+
 		}
-		
+
 		close(filefd);
-		
+
 	}
-	
-	
+
+
 	return file_buffer;
 
 }
@@ -281,7 +281,7 @@
 
 		if(c == '\n' || c == '\r')
 			break;
-			
+
 		i++;
 	}
 
@@ -303,7 +303,7 @@
 		return 1;
 
 	return 0;
-	
+
 }
 
 
@@ -313,7 +313,7 @@
 
 
 int dir_exist(char *dirname)
-{	
+{
 	struct stat stat_buf;
 
 	memset(&stat_buf, 0, sizeof(struct stat));
@@ -342,7 +342,7 @@
 			if(strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name, ".") != 0)
 			{
 				snprintf(path, 1000, "%s/%s", dirname, entry->d_name);
-				
+
 				if(dir_exist(path))
 				{
 					dir_remove(path);
@@ -351,12 +351,12 @@
 				{
 					unlink(path);
 				}
-				
+
 			}
 		}
 
 		closedir(dir_ptr);
-	
+
 		rmdir(dirname);
 	}
 
@@ -370,14 +370,14 @@
 {
 	int slashcount = 0;
 	int i=0;
-	
+
 	while(i<strlen(path))
 	{
 		if(path[i] == '/')
 			slashcount++;
 		i++;
 	}
-	
+
 	return slashcount;
 }
 
@@ -390,37 +390,39 @@
 	unsigned int line_num;
 	int i = 0;
 	int highstlevel=-1, support=0;
-	
+
 	char mpstr[250], optstr[250];
-	
+
 	mountsstr = file_read("/proc/mounts");
-	
+
 	if(mountsstr != NULL)
 	{
 		linestrs = split_string(mountsstr, '\n', &line_num);
-	
+
 		while(i < line_num)
 		{
 			sscanf(linestrs[i], "%*s %249s %*s %249s", mpstr, optstr);
-		
-		
+
+
 			if(strncmp(mpstr, targetpath, strlen(mpstr)) == 0)
 			{
 				if(dir_getlevel(mpstr) > highstlevel)
 				{
 					if(strstr(optstr, "tagxid") != NULL)
 						support=1;
+					else if(strstr(optstr, "tag") != NULL)
+						support=1;
 					else support=0;
 				}
 			}
-		
+
 			i++;
 		}
-	
+
 		free_strings(linestrs, line_num);
 		free(mountsstr);
 	}
-	
+
 	return support;
 }
 

Modified: trunk/daemon/src/userbackup.c
===================================================================
--- trunk/daemon/src/userbackup.c	2009-05-03 13:46:36 UTC (rev 664)
+++ trunk/daemon/src/userbackup.c	2009-05-03 14:32:13 UTC (rev 665)
@@ -161,8 +161,10 @@
 	struct ovcp_data_st *arg0, *arg1;
 	struct ovcp_response_st *response;
 
-	char *name, *homedir, *backupdir, *userbackupdir, *backupname;
+	char path[BUF_SIZE+1];
 
+	char *name, *homedir, *backupdir, *userbackupdir, *backupname, *context;
+
 	arg0 = ovcp_request_get_arg(request, 0);
 	name = (char *)ovcp_data_get(arg0);
 
@@ -201,24 +203,31 @@
 		}
 		else
 		{
+			sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/context", NULL);
+			context = file_read(path);
+			trim_string(context);
+
+			if(fs_tagxid_support(homedir)) execb_cmd("chxid", "chxid", "-c",  context, "-R", "--", homedir, NULL);
+
+
 			ovcp_response_add_string(response, "Success");
 		}
 	}
 	execb_cmd("rm", "rm", "-rf", backupdir, NULL);
 	free(backupdir);
+	free(context);
 	free(userbackupdir);
 	free(homedir);
 	return response;
 
 }
 
-
 struct ovcp_response_st *refresh_userbackups(struct ovcp_request_st *request)
 {
 	struct ovcp_data_st *arg0, *arg1;
 	struct ovcp_response_st *response;
 
-	char *name, *homedir, *userbackupdir, *backupname;
+	char *name, *homedir, *userbackupdir, *backupname, *backupnamenew, *userbackupdirnew;
 	int ret=0;
 
 	arg0 = ovcp_request_get_arg(request, 0);
@@ -249,17 +258,61 @@
 			ovcp_response_add_string(response, "Success");
 		}
 	}
-	free(userbackupdir);
-	free(homedir);
-	return response;
 
-}
+	char *min, *hour, *day, *month, *year;
 
+	struct tm *currentdate;
+	time_t timestamp = time(0);
+	currentdate = localtime(&timestamp);
 
+	min = (char *)malloc(4);
+    if(currentdate->tm_min < 10) {
+            snprintf(min, 3, "0%i", currentdate->tm_min);
+    }
+    else {
+            snprintf(min, 3, "%i", currentdate->tm_min);
+    }
+    hour = (char *)malloc(4);
+    if(currentdate->tm_hour < 10) {
+            snprintf(hour, 3, "0%i", currentdate->tm_hour);
+    }
+    else {
+            snprintf(hour, 3, "%i", currentdate->tm_hour);
+    }
+    day = (char *)malloc(4);
+    if(currentdate->tm_mday < 10) {
+            snprintf(day, 3, "0%i", currentdate->tm_mday);
+    }
+    else {
+            snprintf(day, 3, "%i", currentdate->tm_mday);
+    }
+    month = (char *)malloc(4);
+    if(currentdate->tm_mon < 10) {
+            snprintf(month, 3, "0%i", currentdate->tm_mon+1);
+    }
+    else {
+            snprintf(month, 3, "%i", currentdate->tm_mon+1);
+    }
+    year = (char *)malloc(6);
+    snprintf(year, 5, "%i", currentdate->tm_year+1900);
 
+	backupnamenew = concat(name, "_", year, ".", month, ".", day, "_", hour, ":", min, NULL);
+	userbackupdirnew = concat(global_settings.userbackup_dir, "/", backupnamenew, NULL);
 
+	ret = execb_cmd("mv", "mv", userbackupdir, userbackupdirnew, NULL);
 
+	free(min);
+	free(hour);
+	free(day);
+	free(month);
+	free(year);
+	free(userbackupdir);
+	free(userbackupdirnew);
+	free(backupnamenew);
+	free(homedir);
+	return response;
 
+}
 
 struct ovcp_response_st *delete_userbackups(struct ovcp_request_st *request)
 {



More information about the Commits mailing list