M6 KVM avatar M6 KVM committed 43bfe38 Draft

Define Log(), which accepts options and log level for the current message.

Comments (0)

Files changed (1)

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 
 #include "dlhomesym.h"
 );
 static unsigned short int IsExcludedHome(const char *HomeEnt);
 static int LinkCleanup(
+	const struct s_opts *const Opts,
 	const char *HomeRootLnk,
 	char **UserList, const int UserListMarker
 );
 static int ProcessOptions(struct s_opts *Opts, int ArgC, char **ArgV);
+static void Log(
+	const struct s_opts *const Opts,
+	const unsigned int Level,
+	const char *Format, ...
+);
 /*-------------------------------------------------------------------------*/
 static int EnumHomes(
 	char **Homes, const int MaxHomes,
 }
 /*-------------------------------------------------------------------------*/
 static int LinkCleanup(
+	const struct s_opts *const Opts,
 	const char *HomeRootLnk,
 	char **UserList, const int UserListMarker
 ) {
 			fullLinkPath = GluePath(HomeRootLnk, ent->d_name);
 			if ( !fullLinkPath ) continue;
 
-			fprintf(stderr, "Doing stat on %s\n", fullLinkPath);
+			Log(Opts, 10, "Doing stat on %s", fullLinkPath);
 			if ( lstat(fullLinkPath, &statEnt) == 0 ) {
 				if ( !S_ISLNK(statEnt.st_mode) )
 					continue;
 	return 0;
 }
 /*-------------------------------------------------------------------------*/
+static void Log(
+	const struct s_opts *const Opts,
+	const unsigned int Level,
+	const char *Format, ...
+) {
+	va_list args;
+
+	va_start(args, Format);
+	if ( Opts->debug_level >= Level ) {
+		vfprintf(stderr, Format, args);
+		fputs("\n", stderr);
+	}
+	va_end(args);
+	return;
+}
+/*-------------------------------------------------------------------------*/
 int main(int argc, char *argv[])
 {
 	static struct s_opts opts;
 	}
 	/* Just debug to see what the userList consists of */
 	DumpUserList(userList, userListMarker);
-	nCleanup = LinkCleanup(homeRootLnk, userList, userListMarker);
+	nCleanup = LinkCleanup(&opts, homeRootLnk, userList, userListMarker);
 	if ( nCleanup < 0 ) {
 		fprintf(
 			stderr, "Error cleaning links from %s\n",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.