1// Check that exceeding RLIMIT_FSIZE fails with EFBIG
2// rather than terminating the process with SIGXFSZ.
3'use strict';
4const common = require('../common');
5const tmpdir = require('../common/tmpdir');
6
7const assert = require('assert');
8const child_process = require('child_process');
9const fs = require('fs');
10const path = require('path');
11
12if (common.isWindows)
13  common.skip('no RLIMIT_FSIZE on Windows');
14
15if (process.config.variables.node_shared)
16  common.skip('SIGXFSZ signal handler not installed in shared library mode');
17
18if (process.argv[2] === 'child') {
19  const filename = path.join(tmpdir.path, 'efbig.txt');
20  tmpdir.refresh();
21  fs.writeFileSync(filename, '.'.repeat(1 << 16));  // Exceeds RLIMIT_FSIZE.
22} else {
23  const cmd = `ulimit -f 1 && '${process.execPath}' '${__filename}' child`;
24  const result = child_process.spawnSync('/bin/sh', ['-c', cmd]);
25  const haystack = result.stderr.toString();
26  const needle = 'Error: EFBIG: file too large, write';
27  const ok = haystack.includes(needle);
28  if (!ok) console.error(haystack);
29  assert(ok);
30  assert.strictEqual(result.status, 1);
31  assert.strictEqual(result.stdout.toString(), '');
32}
33