diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index b0a6295ad189..d895c0dde12c 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -350,10 +350,11 @@ def main(): deep_update(data, json.loads(args.additional_data)) if args.from_db: + use_unix_sock = True if os.getuid() == 0 else False if args.namespace is None: - configdb = ConfigDBPipeConnector(use_unix_socket_path=True, **db_kwargs) + configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, **db_kwargs) else: - configdb = ConfigDBPipeConnector(use_unix_socket_path=True, namespace=args.namespace, **db_kwargs) + configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, namespace=args.namespace, **db_kwargs) configdb.connect() deep_update(data, FormatConverter.db_to_output(configdb.get_config()))