Commit Graph
154 Commits
Author SHA1 Message Date
Alexey MilovidovandGitHub 842b133f8d Merge pull request #100399 from ClickHouse/clang-tidy-init-variables
Enable clang-tidy check for uninitialized variables
2026-05-31 21:56:29 -07:00
Alexey Milovidov a4a69d3774 Merge remote-tracking branch 'origin/master' into clang-tidy-init-variables
# Conflicts:
#	src/Client/BuzzHouse/Generator/QueryOracle.h
#	src/Functions/hilbertEncode.cpp
#	src/Interpreters/ProfileEventsExt.h
#	src/Storages/Statistics/ConditionSelectivityEstimator.cpp
#	src/Storages/Statistics/Statistics.cpp
#	src/Storages/Statistics/tests/gtest_stats.cpp
2026-05-19 16:20:47 +00:00
Alexey Milovidov 7a2f9f408a Merge remote-tracking branch 'origin/master' into fix-compiler-warnings 2026-05-19 15:05:56 +00:00
Raúl MarínandClaude Opus 4.7 88cf709ca1 Share shellQuote and apply it to remaining shell sinks
Move the `shellQuote` helper out of `clickhouse install` into
`Common/shellQuote.h` so it can be reused. Apply it to two more
shell-command construction sites:

- `formatWithSudo` on FreeBSD wraps the inner command in `su -c '...'`.
  All current callers pass static literals, but an embedded single
  quote would break the wrapper. Quote the command via `shellQuote`
  so future callers can pass arbitrary strings safely.
- `clickhouse git-import` interpolates a commit hash parsed from
  `git log --pretty=%H` into `git show ... {hash}` and runs it via
  `/bin/sh -c`. `%H` is hex-only today, but a hand-crafted hash list
  or a future format change should not be able to inject shell
  syntax through the input.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-18 14:50:27 +00:00
Raúl MarínandClaude Opus 4.7 7bc5388dde Quote shell arguments in clickhouse install
`changeOwnership`, `createGroup`, `createUser`, and the `setcap`
invocation in `clickhouse install` interpolated CLI-controlled values
(`--user`, `--group`, `--log-path`, `--data-path`, `--pid-path`,
`--config-path`, `--binary-path`, `--prefix`) directly into shell
command strings passed to `/bin/sh -c`. The `shellQuote` helper
already used by the sudo invocation in the same file was not applied
elsewhere. Wrap every interpolated value in `shellQuote` so shell
metacharacters in CLI arguments cannot be interpreted by the shell.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-18 14:41:03 +00:00
Alexey Milovidov 9567f0d9ba Merge remote-tracking branch 'origin/master' into clang-tidy-init-variables
# Conflicts:
#	src/Processors/QueryPlan/Optimizations/Optimizations.h
#	src/Storages/MaterializedView/RefreshTask.cpp
2026-05-08 03:15:33 +00:00
Alexey Milovidov 7d54e33c7c Merge remote-tracking branch 'origin/master' into fix-compiler-warnings
# Conflicts:
#	programs/main.cpp
2026-05-06 03:18:15 +00:00
Alexey Milovidov f0347457c1 Address review: only apply --group when explicitly specified
`--group` for `clickhouse start` / `restart` had a default value of
`clickhouse` purely for documentation. The launcher applied it
unconditionally on the `sudo` path, so

    clickhouse start --user alice

was silently expanded to `sudo --preserve-env -u alice -g clickhouse ...`.
That fails when `alice` is not a member of the `clickhouse` group,
which is a behavior regression for users who only ever passed `--user`.

Clear `group` in `mainEntryClickHouseStart` and `mainEntryClickHouseRestart`
when `options["group"].defaulted()` is true, so the default is shown in
`--help` but not applied to the spawned server. The `no-sudo` path then
runs `clickhouse su user:`, where `setUserAndGroup` falls back to the
user's primary group.
2026-05-01 03:50:59 +00:00
Alexey MilovidovandClaude Opus 4.7 187bd4bb08 Address review: apply --group on sudo path of clickhouse start
The `--group` option for `clickhouse start` / `restart` was only honored on
the `--no-sudo` branch (`clickhouse su user:group ...`). On the default path
the command was built as `sudo --preserve-env -u <user> ...`, with no `-g`,
so the group was silently ignored.

Pass `-g <group>` to `sudo` (shell-quoted) when `group` is non-empty so the
advertised CLI option takes effect on both code paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-04-29 09:54:07 +00:00
Alexey MilovidovandClaude Opus 4.7 624c852ffe Shell-escape interpolated values in clickhouse start / restart
The previous attempt to harden the `--no-sudo` and `sudo` paths in
`clickhouse start` wrapped interpolated `user`, `group`, and binary
paths in single quotes only. This is insufficient: a value containing
a single quote (e.g. `bob';rm -rf /;'`) still breaks out because
single quotes do not nest.

Introduce a POSIX-compliant `shellQuote` helper in `Install.cpp` and
apply it to every user-controlled field interpolated into the `su` /
`sudo` command strings: `executable`, `config`, `pid_file`,
`binary`, `user`, and `group`. The helper replaces any `'` inside
the value with `'\''` before re-wrapping, which is the standard POSIX
idiom and safe against arbitrary byte content.

While CLI arguments to `clickhouse start` are not typically attacker
controlled (the caller already runs the binary), defense-in-depth is
worthwhile: these commands go through `/bin/sh -c` via
`ShellCommand::execute`, and unquoted interpolation has been flagged
as a hazard in code review.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-04-21 00:12:53 +00:00
Alexey MilovidovandClaude Opus 4.6 463881da74 Address review feedback: stderr for error help, shell quoting, keeper test
- `printHelp` now takes an `std::ostream &` parameter: explicit `help`
  writes to stdout, while `printHelpOnError` (mistyped commands) writes
  to stderr, preserving the error-output contract for scripts.
- Shell-quote binary path and user:group in the `--no-sudo` branch of
  `clickhouse start` to prevent command injection via crafted CLI args.
- Make the keeper availability check in the help return codes test more
  precise: match `clickhouse keeper [args]` exactly instead of bare
  `keeper` which could false-match `keeper-converter` etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-09 20:27:13 +00:00
Alexey MilovidovandClaude Opus 4.6 48426ad1a6 Fix issues that caused the revert of the original help improvements
The original PR #96025 was reverted (#98038) because:
1. The install completion message showed wrong relative paths like
   `var/run/clickhouse-server` instead of absolute `/var/run/clickhouse-server`.
   This happened because `options.contains()` returns true even for options
   with default values in boost::program_options. Fix: use `defaulted()`
   to only include options that the user explicitly specified.
2. The install completion message did not suggest `sudo` for the
   start/restart command. This happened because `getuid() != 0` is false
   when install runs as root via sudo, but the user returns to their
   unprivileged shell afterward. Fix: always suggest sudo (matching the
   original behavior).

Also address review feedback:
- Fix `clickhouse-client` help: remove misleading "initial table definition"
  (a `clickhouse-local` concept) from usage line
- Fix typo: "as command line tool" → "as a command line tool"
- Fix `clickhouse-local` help grammar: "After you can execute" → "After that,
  you can execute", "in first query" → "in the first query"
- Make keeper `--help` test robust for builds without `ENABLE_CLICKHOUSE_KEEPER`

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-09 08:06:11 +00:00
Alexey Milovidov 2e15ae037c Merge remote-tracking branch 'origin/master' into revert-98038-revert-96025-clickhouse-help 2026-03-30 07:43:50 +00:00
Alexey Milovidov fb4cee51f5 Merge remote-tracking branch 'origin/master' into clang-tidy-init-variables 2026-03-30 02:51:23 +00:00
Alexey Milovidov 01d5c6a84c Merge remote-tracking branch 'origin/master' into fix-compiler-warnings 2026-03-29 23:20:54 +00:00
Alexey MilovidovandGitHub 8b819651a9 Merge branch 'master' into revert-98038-revert-96025-clickhouse-help 2026-03-28 23:50:35 +01:00
Alexey MilovidovandClaude Opus 4.6 8b47d200d5 Enable -Wmissing-prototypes compiler warning
Add `static` to file-local functions and forward declarations
for cross-TU functions to satisfy `-Wmissing-prototypes`.

This ensures all functions have visible prototypes before their
definitions, improving code quality and catching accidental
linkage issues.

Reference: https://github.com/ClickHouse/ClickHouse/issues/76944

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-03-27 20:11:07 +00:00
Alexey MilovidovandClaude Opus 4.6 4d6c92f0d2 Address review comments: remove stale #embed comments and add missing deps
- Remove "CMake doesn't recognize changes in #embed-ed files" comments
  from all files, since this PR now tracks those dependencies.
- Add conditional `OBJECT_DEPENDS` for `FrequencyHolder.cpp` NLP blobs
  (guarded by `if (EXISTS ...)` for when the submodule is not checked out).
- Add `OBJECT_DEPENDS` for `attachInformationSchemaTables.cpp` which was
  also missing dependency tracking for its embedded SQL files.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-03-27 00:40:29 +01:00
Alexey Milovidov 9f6854b4b4 Merge branch 'master' into clang-tidy-init-variables
# Conflicts:
#	src/Coordination/KeeperSnapshotManager.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/FileNamesGenerator.h
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDataObjectInfo.h
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Snapshot.h
2026-03-24 19:34:14 +00:00
Alexey MilovidovandClaude Opus 4.6 d249cd3f9d Fix clang-tidy cppcoreguidelines-init-variables and hicpp-member-init after merge with master
New code from master introduced uninitialized variables and struct
members that trigger the newly enabled clang-tidy checks. Fix all 368
errors by adding default initializers (`{}`, `= 0`, `= nullptr`) to
local variables and struct/class member declarations.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100399&sha=78a76ff56fc5747009e8c34795b8a3cb2432eeae&name_0=PR

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-03-24 11:25:35 +00:00
Robert Schulze 898b0d8270 Add comments 2026-03-15 19:01:55 +00:00
Alexey MilovidovandGitHub 85164c93d4 Revert "Revert "Improve help output for ClickHouse applications"" 2026-02-27 00:49:00 +01:00
Alexey MilovidovandGitHub e8654c51eb Revert "Improve help output for ClickHouse applications" 2026-02-26 07:51:17 +01:00
Raúl MarínandClaude Opus 4.6 9aa8e4ed27 Move ErrnoException from Exception.h to its own header
Extract `ErrnoException` into `Common/ErrnoException.h` to reduce the
include footprint of `Exception.h`. This removes `<base/errnoToString.h>`
and `<cerrno>` from `Exception.h`, which is included by ~95% of all
translation units.

All files referencing `ErrnoException` now include the new header
directly. Files that used `errnoToString` without `ErrnoException`
got an explicit `<base/errnoToString.h>` include.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-20 13:47:23 +01:00
Alexey MilovidovandClaude Opus 4.5 d010338fd8 Add --group option and pass install options to suggested start command
- Add --group option to start and restart commands
- Use clickhouse su instead of sudo when --no-sudo is set
- Pass --prefix, --pid-path, --config-path, --binary-path, --user, --group
  from install to the suggested start/restart command

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 07:18:40 +01:00
Alexey MilovidovandClaude Opus 4.5 62ccfbd3aa Improve help output for ClickHouse applications
This commit improves the help output for all ClickHouse applications:

- Add `clickhouse help` command that lists all available subcommands
- Return exit code 0 for all help messages (previously some returned 1)
- Output help messages to stdout instead of stderr
- Use "clickhouse <cmd>" format instead of argv[0] in help messages
- Add dynamic `app_name` detection for `clickhouse client` and `clickhouse local`
  to show correct invocation name based on how the binary was called
- Add `--no-sudo` option for `clickhouse start` and `clickhouse restart`
  for environments without sudo (e.g., Docker containers)
- Add detailed help headers and footers for client and local with usage examples

Closes #58244

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 07:12:44 +01:00
Raúl Marín 5a5673539d Missing files 2026-01-08 17:14:36 +01:00
Raúl Marín 2fb21c0e5f Fix builds 2025-12-18 19:28:02 +01:00
Raúl Marín a8d196b58d Remove StackTrace.h from Exception.h 2025-12-18 12:04:33 +01:00
Azat Khuzhin 2e630bb588 Improve --help for status/start/restart/stop 2025-09-15 08:53:47 +02:00
Azat Khuzhin b2b4040023 Bundle chdig into clickhouse binary
Previously it was only shipped as part of the client package, now it
will be bundled into the binary, and will be available as:
- clickhouse chdig
- clickhouse-chdig
- chdig

Note, that since now chdig will not be linked, we can remove all
quirks for this, that has been done in #79666
2025-06-23 17:06:25 +02:00
Azat Khuzhin 24d4607d21 clickhouse-stop: kill only processes that are passed via pid file 2025-06-07 17:21:20 +02:00
Azat Khuzhin 0fea21845d clickhouse-stop: ignore pid file does not exist only during polling 2025-06-07 17:21:20 +02:00
Azat Khuzhin 8e2a8a33ce clickhouse-stop: fix message for killing 2025-06-07 17:21:20 +02:00
Nikita Mikhaylov ee12273297 Improve the SSH protocol 2025-03-18 14:53:35 +01:00
Alexey MilovidovandGitHub b999483404 Merge pull request #73827 from ClickHouse/install-better-message
Better message during installation
2024-12-27 17:31:47 +00:00
Alexey Milovidov ff7f242ebf Ask before output binary data into terminal 2024-12-26 07:31:10 +01:00
Alexey Milovidov f1e59ccfbe Better message during installation 2024-12-25 08:04:55 +01:00
Sema Checherinda f1ab911910 cancel or finalize write buffer 2024-11-11 11:37:12 +01:00
Konstantin Bogdanov 67c1e89d90 Apply linter changes 2024-10-06 12:29:20 +02:00
Alexey Milovidov 224e1940ae Useless changes 2024-05-09 03:58:34 +02:00
Alexander Tokmakov 91d4284bdf don't allow relative paths when installing 2024-04-15 16:21:09 +02:00
Robert Schulze 752a69b6dd Minor fixups 2024-04-10 17:37:24 +00:00
yokofly e4cb27eda3 fix macOS binary install
the usr/bin is not suitable for macOS
https://superuser.com/questions/933019/sudo-cant-create-file-in-usr-bin-in-el-capitan
after apply this patch, we can `sudo ./clickhouse --install` on MacOS
2024-04-10 21:27:48 +08:00
Alexey Milovidov a6dbaf5408 dhparams are not enabled by default 2024-04-06 21:45:26 +02:00
Nikita Mikhaylov 2bc4d27ac6 Bye bye 2024-03-07 19:24:39 +00:00
Azat Khuzhin 7fb31fe160 Remove ability to disable generic clickhouse components
Components like client/server/... are very generic, and there is no
point in disabling them, since it does not reduce amount of compiled
code a lot anyway (just a few modules for entrypoints, everything else
is already included in the clickhouse binary), and eventually they are
just symlinks to the clickhouse binary.

But there are few, that requires extra libraries, like ODBC bridge or
keeper components (and there is also standalone keeper binary compiled
with musl), those had been kept.

Also add some descriptions for some utils and change exit code to 0 for
--help.

Signed-off-by: Azat Khuzhin <[email protected]>
2024-02-12 11:10:00 +01:00
Alexey Milovidov a585ae60a8 English (somewhat incomplete) 2024-02-09 00:30:29 +01:00
Alexey Milovidov 1b91b7b999 Better logs in CI and non-interactive install 2024-02-09 00:16:15 +01:00
Raúl Marín b269f87f4c Better text_log with ErrnoException 2023-12-15 19:27:56 +01:00