|
| 1 | +// Check that exceeding RLIMIT_FSIZE fails with EFBIG |
| 2 | +// rather than terminating the process with SIGXFSZ. |
| 3 | +'use strict'; |
| 4 | +const common = require('../common'); |
| 5 | +const tmpdir = require('../common/tmpdir'); |
| 6 | + |
| 7 | +const assert = require('assert'); |
| 8 | +const child_process = require('child_process'); |
| 9 | +const fs = require('fs'); |
| 10 | +const path = require('path'); |
| 11 | + |
| 12 | +if (common.isWindows) |
| 13 | + common.skip('no RLIMIT_FSIZE on Windows'); |
| 14 | + |
| 15 | +if (process.config.variables.node_shared) |
| 16 | + common.skip('SIGXFSZ signal handler not installed in shared library mode'); |
| 17 | + |
| 18 | +if (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 | +} |
0 commit comments