<commit_before>#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "util.h"
#include "syscall.h"
#include "uts_ns.h"
#include "ipc_ns.h"

int switch_ns(int pid, int type, char *ns)
{
	char buf[32];
	int nsfd, ret;

	snprintf(buf, sizeof(buf), "/proc/%d/ns/%s", pid, ns);
	nsfd = open(buf, O_RDONLY);
	if (nsfd < 0) {
		pr_perror("Can't open ipcns file");
		goto out;
	}

	ret = setns(nsfd, type);
	if (ret < 0)
		pr_perror("Can't setns %d/%s", pid, ns);

	close(nsfd);
out:
	return ret;
}

static int do_dump_namespaces(int ns_pid, unsigned int ns_flags)
{
	struct cr_fdset *fdset;
	int ret;

	fdset = cr_fdset_open(ns_pid, CR_FD_DESC_NS, NULL);
	if (fdset == NULL)
		return -1;

	if (ns_flags & CLONE_NEWUTS) {
		ret = dump_uts_ns(ns_pid, fdset);
		if (ret < 0)
			goto err;
	}
	if (ns_flags & CLONE_NEWIPC) {
		ret = dump_ipc_ns(ns_pid, fdset);
		if (ret < 0)
			goto err;
	}
err:
	close_cr_fdset(&fdset);
	return ret;

}

int dump_namespaces(int ns_pid, unsigned int ns_flags)
{
	int pid, ret, status;

	/*
	 * The setns syscall is cool, we can switch to the other
	 * namespace and then return back to our initial one, but
	 * for me it's much easier just to fork another task and
	 * let it do the job, all the more so it can be done in
	 * parallel with task dumping routine.
	 *
	 * However, the question how to dump sockets from the target
	 * net namesapce with this is still open
	 */

	pr_info("Dumping %d's namespaces\n", ns_pid);

	pid = fork();<commit_msg>namespaces: Eliminate uninitialized 'ret' usage<commit_after>#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "util.h"
#include "syscall.h"
#include "uts_ns.h"
#include "ipc_ns.h"

int switch_ns(int pid, int type, char *ns)
{
	char buf[32];
	int nsfd;
	int ret = -1;

	snprintf(buf, sizeof(buf), "/proc/%d/ns/%s", pid, ns);
	nsfd = open(buf, O_RDONLY);
	if (nsfd < 0) {
		pr_perror("Can't open ipcns file");
		goto out;
	}

	ret = setns(nsfd, type);
	if (ret < 0)
		pr_perror("Can't setns %d/%s", pid, ns);

	close(nsfd);
out:
	return ret;
}

static int do_dump_namespaces(int ns_pid, unsigned int ns_flags)
{
	struct cr_fdset *fdset;
	int ret = 0;

	fdset = cr_fdset_open(ns_pid, CR_FD_DESC_NS, NULL);
	if (fdset == NULL)
		return -1;

	if (ns_flags & CLONE_NEWUTS) {
		ret = dump_uts_ns(ns_pid, fdset);
		if (ret < 0)
			goto err;
	}
	if (ns_flags & CLONE_NEWIPC) {
		ret = dump_ipc_ns(ns_pid, fdset);
		if (ret < 0)
			goto err;
	}
err:
	close_cr_fdset(&fdset);
	return ret;

}

int dump_namespaces(int ns_pid, unsigned int ns_flags)
{
	int pid, status;
	int ret = 0;

	/*
	 * The setns syscall is cool, we can switch to the other
	 * namespace and then return back to our initial one, but
	 * for me it's much easier just to fork another task and
	 * let it do the job, all the more so it can be done in
	 * parallel with task dumping routine.
	 *
	 * However, the question how to dump sockets from the target
	 * net namesapce with this is still open
	 */

	pr_info("Dumping %d's namespaces\n", ns_pid);

	pid = fork();
{'fraction_non_alphanumeric': 0.130234091658424, 'fraction_numerical': 0.00560501153972964, 'mean_word_length': 3.682098765432099, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '857211', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1213, 'n_words': 386}