---
name: "ll2_write_entry"
section: "3"
platform: "linux"
package: "util-linux-libs"
version: "2.42.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ll2_write_entry"
---

# ll2\_write\_entry(3)

Writes a new entry into the database.

## NAME

ll2\_write\_entry - Writes a new entry into the database.

## SYNOPSIS

**#include \<lastlog2.h\>**

**int ll2\_write\_entry (struct ll2\_context \****context***, const char \****user***,** **int64\_t** *ll\_time***, const char \****tty***,** **const char \****rhost***, const char \****pam\_service***,** **char \*\****error***);**

## DESCRIPTION

*Writes a new entry into database, which is defined in context.* *If context is NULL, the default database, defined in LL2\_DEFAULT\_DATABASE,* *will be taken.*

```
time_t login_time = time(0); // Get the system time
char   *error = NULL;
const  char *user = "root";
int ret = ll2_write_entry (NULL, user, login_time, "pts/0",
                            "192.168.122.1", NULL, &error);
```

*pam\_service is the service or instance name which has generated the entry (optional).*

## RETURN VALUE

*Returns 0 on success, -ENOMEM or -1 on other failure.* *error contains an error string if the return value is -1.* *error is not guaranteed to contain an error string, could also be NULL.* *error should be freed by the caller.*

## AUTHORS

*Thorsten Kukuk \<kukuk@suse.de\>*

## SEE ALSO

**lastlog2***(3),* **ll2\_new\_context***(3),* **ll2\_unref\_context***(3),* **ll2\_read\_all***(3),* **ll2\_read\_entry***(3),* **ll2\_update\_login\_time***(3),* **ll2\_remove\_entry***(3),* **ll2\_rename\_user***(3),* **ll2\_import\_lastlog***(3)*

## REPORTING BUGS

*For bug reports, use the* *issue tracker \<https://github.com/util-linux/util-linux/issues\>.*

## AVAILABILITY

*The* **liblastlog2** *library is part of the util-linux package since version 2.40. It can be downloaded from* *Linux Kernel Archive \<https://www.kernel.org/pub/linux/utils/util-linux/\>.*
