lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.00.0905300939450.14994@gandalf.stny.rr.com>
Date:	Sat, 30 May 2009 09:44:10 -0400 (EDT)
From:	Steven Rostedt <rostedt@...dmis.org>
To:	GeunSik Lim <leemgs1@...il.com>
cc:	Greg KH <greg@...ah.com>,
	linux-kernel <linux-kernel@...r.kernel.org>, trivial@...nel.org,
	balagi@...tmail.de, bgamari@...il.com, Ingo Molnar <mingo@...e.hu>,
	inaky.perez-gonzalez@...el.com
Subject: Re: [RFC V2 PATCH]debugfs:Fix terminology inconsistency of dir name
  to mount debugfs filesystem.


On Sat, 30 May 2009, GeunSik Lim wrote:
> @@ -1202,11 +1208,57 @@ something like this simple program:
> 
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <string.h>
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <fcntl.h>
>  #include <unistd.h>
> 
> +#define _STR(x) #x
> +#define STR(x) _STR(x)
> +#define MAX_PATH 256
> +
> +const char *find_debugfs(char *file_name)
> +{
> +       static char debugfs[MAX_PATH+1];
> +       static int debugfs_found;
> +       char type[100];
> +       FILE *fp;
> +       int size;
> +
> +       if (debugfs_found)
> +               return debugfs;
> +
> +       if ((fp = fopen("/proc/mounts","r")) == NULL) {
> +               perror("/proc/mounts");
> +               return NULL;
> +       }
> +
> +       while (fscanf(fp, "%*s %"
> +                     STR(MAX_PATH)
> +                     "s %99s %*s %*d %*d\n",
> +                     debugfs, type) == 2) {
> +               if (strcmp(type, "debugfs") == 0)
> +                       break;
> +       }
> +       fclose(fp);
> +
> +       if (strcmp(type, "debugfs") != 0) {
> +               fprintf(stderr, "debugfs not mounted");
> +               return NULL;
> +       }
> +
> +       debugfs_found = 1;
> +
> +       size = MAX_PATH - strlen(debugfs);
> +       strncat(debugfs, "/tracing/", size);
> +
> +       size = MAX_PATH - strlen(debugfs);
> +       strncat(debugfs, file_name, size);

You need to make two functions. One to find the debugfs and one to add the 
file. The "debugfs_found" will make the function return just the first 
file_name every time. Something like this: (remove the file_name from 
find_debugfs).

const char *tracing_file(const char *file_name)
{
	static char trace_file[MAX_PATH+1];

	snprintf(trace_file, MAX_PATH, "%s/%s", find_debugfs(), file_name);

	return trace_file;
}

The above is not thread safe, but is OK for non threaded programs.

-- Steve

> +
> +       return debugfs;
> +}
> +
>  int main (int argc, char **argv)
>  {
>          if (argc < 1)
> @@ -1217,12 +1269,12 @@ int main (int argc, char **argv)
>                  char line[64];
>                  int s;
> 
> -                ffd = open("/debug/tracing/current_tracer", O_WRONLY);
> +                ffd = open(find_debugfs("current_tracer"), O_WRONLY);
>                  if (ffd < 0)
>                          exit(-1);
>                  write(ffd, "nop", 3);
> 
> -                fd = open("/debug/tracing/set_ftrace_pid", O_WRONLY);
> +                fd = open(find_debugfs("set_ftrace_pid"), O_WRONLY);
>                  s = sprintf(line, "%d\n", getpid());
>                  write(fd, line, s);
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ