cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 178ecdabd556dd2e9888f9c8b3f96b551d76df01 576 bytes (raw)
$ git show HEAD:cloexec_from.c	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
/*
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */
#include "cmogstored.h"

/*
 * this function is only called in a vforked child (for iostat)
 * if O_CLOEXEC/SOCK_CLOEXEC is unsupported, or if mog_cloexec_detect()
 * detects those flags are broken.
 */
void mog_cloexec_from(int lowfd) /* vfork-safe */
{
	int fd;
	int last_good = lowfd;

	for (fd = lowfd; fd < INT_MAX; fd++) {
		if (mog_set_cloexec(fd, true) == 0)
			last_good = fd;
		if ((last_good + 1024) < fd)
			break;
	}
}

git clone https://yhbt.net/cmogstored.git